I've run into the problem that currently it is not possible to open Unicode path via OpenCV (4.1.1.26) in python 3.7. I'm trying to develop the best practice to do that.
When the path contains Unicode we should use something described here (u'D:\ö\handschuh.jpg' or '测试目录/test.jpg').
The first thing that I've tried to find is how to detect if a string contains Unicode. As I found here - all strings in python 3 are in Unicode.
For now, I'm using such workaround:
import numpy as np
import cv2
def read(impath, flag=-1):
try:
image = cv2.imread(impath, flag)
assert image is not None, ("Image is {im} check the path {path}".format (im=image, path=impath))
except :
image = cv2.imdecode(np.fromfile(impath, dtype=np.uint8), cv2.IMREAD_UNCHANGED)
assert image is not None, ("Image is {im} check the path {path}".format(im=image, path=impath))
return image
That is obviously not the best way to do that as you should never use try\except pattern.
What are the suggestions?