Describe the bug
Opencv is not able to load images with special characters in the filename.
To Reproduce
1) Take any image file rename the filename add a special character.
In my case it was the micron symbol "10碌m"
2) load the image with the open_img function
fn = Path(r'c:\data\test image (6-9碌m).jpg')
data = open_img(fn)
3) see error
C:\Anaconda\envs\ice\lib\site-packages\icevision\core\record_mixins.py in _load(self)
79
80 def _load(self):
---> 81 self.img = open_img(self.filepath)
82 # TODO, HACK: is it correct to overwrite height and width here?
83 self.height, self.width, _ = self.img.shape
C:\Anaconda\envs\ice\lib\site-packages\icevision\utils\imageio.py in open_img(fn, gray)
8 raise ValueError(f"File {fn} does not exists")
9 color = cv2.COLOR_BGR2GRAY if gray else cv2.COLOR_BGR2RGB
---> 10 return cv2.cvtColor(cv2.imread(str(fn), cv2.IMREAD_UNCHANGED), color)
11
12
error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-vjyn6ztg\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
Desktop (please complete the following information):
Additional context
I know this is not an icevision issue strictly speaking, but it might be worth considering a different library for loading the image, and not using opencv.
We are currently transition to PIL for loading images. Can you check if PIL handles this correctly?
yes it works with PIL
from PIL import Image
im = Image.open(r"image 9碌m.jpg")