every blog every motto: You can do more than you think.
0. Preface
I encountered a problem before, and I encountered it again today, remember it.
1. Text
1.1 problem
When using python to call opencv, the picture cannot be read, and the return result is None, as shown in the following figure:
1.2 Solution
The reason is that the picture read is still in Chinese, so it cannot be read. Make the following improvements:
import os
import cv2 as cv
import numpy as np
def cv_imread(file_path):
"""可读取图片(路径为中文)
:param file_path: 图片路径
:return:
"""
# 可以使用中文路径读取图片
cv_img = cv.imdecode(np.fromfile(file_path, dtype=np.uint8), -1)
return cv_img
file = './数据/201910_A11_3_10r_43c.tif'
img = cv_imread(file)
# print(img)
print(img.shape)
print('-------------------------------------22')
The result is as follows, the picture can be read correctly: