nonetype object has no attribute shape/ cv2.imread cannot read the Chinese path problem

        An error occurred when doing image detection: nonetype object has no attribute shape, indicating that it cannot find the image object. And I tried to use video to read, but it can be read correctly, which means that the error is reported because the picture was not read successfully.

        Later, it was found that it was a path problem. There is no problem with using relative paths and English absolute paths, but the Chinese path cannot be read. In order to meet the needs, the way of reading image data for cv2 has changed a little.

 # file = 'input.jpg'
file = img
#image = cv2.imread(file)#这是初始的方式,是无法读取中文路径的


#将其改变为下面这种形式就可以成功读取了,是从数据内存角度去读取的,中间绕了一下
image=cv2.imdecode(np.fromfile(os.path.join(file), dtype=np.uint8),-1)

Guess you like

Origin blog.csdn.net/weixin_63676550/article/details/129779474