[Opencv] Use opencv-python to read Chinese path pictures

img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), -1)  # 读入完整图片,见下面解释
img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 0)  # 读成灰度
img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 1)  # 读成彩图

The flag -1 after cv2.imdecode should be the same as cv2.imread.

Use the function cv2.imread (filepath, flags) to read in a picture:

filepath: The path of the image to be read.

flags: read the flags of the picture:

  cv2.IMREAD_UNCHANGED (-1): As the name suggests, read the complete picture, including alpha channel. If the data does not contain an alpha channel, the gray image is read as (H, W), and the color image is read as (H, W, 3).

  cv2.IMREAD_GRAYSCALE (0): Read the grayscale image, the shape is (H, W). Color pictures are also read as gray shapes.

  cv2.IMREAD_COLOR (1): The default parameter is to read a color image, ignoring the alpha channel, and the shape is (H, W, 3). Gray maps are also read in colorful shapes.

Images with an alpha channel have not been tested, but it seems that reading -1 is relatively safe.

 

reference:

https://www.cnblogs.com/come-on-baby/p/11386909.html

Published 190 original articles · praised 497 · 2.60 million views +

Guess you like

Origin blog.csdn.net/u013066730/article/details/105392189