Filename contains » character

Hello,
I am new to opencv and completely new to this forum.

I am using opencv2 with python3 under Windows.

I have many directories containing image files which I want to open and display with opencv.
Many file/directory-names contain the character “»”.
I open these files with imread().
imread() returns None.

It definitely depends upon the file/directory name.
Using my scripts with other directories/files with “normal” names works.
As I have many files/directories containing this character and because they are referenced in html-files, renaming them is not an easy option.
I tried quoting the character with a backslash, but this does not help.
I can open and read the files with the normal open() function, so it does not look like a python-problem.

Any help is greatly appreciated.

imread() can indeed only read ascii file names.

as a workaround in python, you can read it in using open() (which can handle funny chars) and then decode it:

f = open("funny».jpg", "r")
b = f.read()
f.close()

b = np.frombuffer(b, dtype=np.uint8)
image = cv2.imdecode(b, cv2.IMREAD_COLOR);
1 Like

Wow, thanks a lot!
This is exactly what I hoped for.

I need to open the image with “rb”, not only “r”, and it works.

python 2 / 3 issue, i think

You are right. In Python3 I need “rb”, in Python2 “r” is OK.
I thought it is a Windows/Linux thing, but it is not.

Thanks again, it is working nicely.

it’s a windows/linux thing for sure.

python 2/3 tries to adhere to standard fopen() semantics. documentation for both python 2.7 and 3.9 clearly states that text mode is the default (when neither t nor b is specified), and text mode may touch newlines.

this newline conversion is only done because windows uses CRLF and historically didn’t understand anything else… but these days it – and most programs running on windows! --have no problems with that.