Ask Your Question
1

imread and Russian language path to img

asked 2018-12-14 02:57:19 -0500

almed gravatar image

updated 2018-12-14 02:59:50 -0500

berak gravatar image

Could you please help with following problem:

When I try to open file with imread and path on file system to this file has Russian latter I catch only blank array. If I change path to English letters only - file upload in right way. In future its will not be possible change names of files to English.

code: img = cv2.imread('E:\folder 3.1\тест.jpg',1) #тест - its a Russian latters

P.s.: I use python and work in windows. Thanks in advance!

Alexander.

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
2

answered 2018-12-14 05:08:34 -0500

almed gravatar image

updated 2018-12-14 05:12:19 -0500

berak gravatar image

I have a solution:

f = open(some_kyrillic_name, "rb")
chunk = f.read()
chunk_arr = np.frombuffer(chunk, dtype=np.uint8)
img = cv2.imdecode(chunk_arr, cv2.IMREAD_COLOR)

Thank for your time, berak!

edit flag offensive delete link more

Comments

problem solved, then ;)

berak gravatar imageberak ( 2018-12-14 05:12:47 -0500 )edit
0

answered 2018-12-14 03:04:25 -0500

berak gravatar image

updated 2018-12-14 04:20:09 -0500

sad as it is maybe, you can only apply ascii strings to imread().

as a workaround, you can load the file using native python methods (which can read unicode paths) and pass it to imdecode:

f = open(some_kyrillic_name, "rb");
bytes = f.read()
image = cv2.imdecode(np.asarray(bytes, np.uint8), cv2.IMREAD_COLOR)
edit flag offensive delete link more

Comments

Thank you fast answer!

But now I have error:TypeError: buf is not a numpy array, neither a scalar

Code: f = open(some_kyrillic_name, "rb") img = cv2.imdecode(f.read(), 1)

almed gravatar imagealmed ( 2018-12-14 04:13:16 -0500 )edit

imdecode() expects a numpy array, so try :

np.asarray(bytes, np.uint8)

instead

berak gravatar imageberak ( 2018-12-14 04:20:45 -0500 )edit

berak, thank you again for fast answer. Does it work on you PC?

Now I have a new one error:ValueError: invalid literal for int() with base 10: b"\xff\xd8\x......

almed gravatar imagealmed ( 2018-12-14 04:42:29 -0500 )edit

sorry, but i don't have any unicode filenames here.

berak gravatar imageberak ( 2018-12-14 04:46:01 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-12-14 02:57:19 -0500

Seen: 204 times

Last updated: Dec 14 '18