Mainly to record some of their own use of Python when some of the problems, or very simple, just every time to check the very troublesome, so simply write a record of their own, if you can solve the problem of the same friends that would be the icing on the cake.
Open the door:
If I want to import two .py files from the Encoder_analyze library (Alpha_utils.py and DCT_utils.py)
If it's in the Encoder_analyze file it can be called directly using import.
An example:
Function definitions in DCT_utils.py
import numpy as np import copy import cv2 #Color space conversion def Get_YUV420(img_path): img = (img_path) yuv2 = (img, cv2.COLOR_BGR2YUV_IYUV) # cv2.COLOR_BGR2YUV_YV12 # cv2.COLOR_BGR2YUV_IYUV # cv2.COLOR_BGR2YUV_I420 width = [1] UV_width = width // 2 height = [0] UV_height = height // 2 # #YUV420 One pixel of UV is equivalent to a block of 2x2 pixels of the Y channel # UV_width =int(width / 4) # UV_heigth = height The #Y channel is the same size as the original image. Y = yuv2[0:height, 0:width] #U channel is behind the Y tmp_U = yuv2[height : height + int(height / 4), 0 : width] tmp_V = yuv2[height + int(height / 4) : height + int(height / 2), 0 : width] U = tmp_U.reshape(UV_width, UV_height) V = tmp_V.reshape(UV_width, UV_height) return Y, U, V
import DCT_utils jpeg_img_path = "D:/neural_network/Webp/dataset_128/dataset/jpeg1/jpeg1_70/" # Color space transformations # Use DCT_utils. for function instantiation, Get_YUV420 is a function written in DCT_utils.py jpeg_Y, jpeg_U, jpeg_V = DCT_utils.Get_YUV420(jpeg_img_path)
But if the .py file being written now is used directly, something else needs to be used.
Just use sys to extend it
import sys ("D:/neural_network/Webp/Encoder_analyze")# Just write the path here
to this article on Python import other folders in the realization of the function of the article is introduced to this, more related Python import function content please search my previous posts or continue to browse the following related articles I hope that you will support me in the future more!