Ask Your Question
0

The imread of python opencv 3.1 can't work with chinese pathdir?

asked 2016-11-26 01:23:57 -0600

The imread command can't read a picture with a chinese path.
import cv2 import numpy as np f=r"D:\OneDrive\火山渣颗粒原始数据\火山渣处理.bmp" img=cv2.imread(f,0)

If use img=cv2.imread(f.encode('gbk'),0), there will raise a TypeError: bad argument type for built-in operatio.

  • OS: win7 64bit
  • Opencv: 3.1
  • Python: 3.5.2

But, when I use Python 2.7 and Opencv 2.4, it work well with:
f=ur"D:\OneDrive\火山渣颗粒原始数据\火山渣_处理.bmp".encode('gbk')

How can I solve this problem?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2016-11-26 01:50:10 -0600

berak gravatar image

updated 2016-11-26 07:59:01 -0600

there is no support for unicode strings in opencv at all, (imread(), imwrite(), putText(), etc) you will have to use plain ascii filenames.

edit flag offensive delete link more

Comments

I'm sure opencv 2.4 work well in 2nd examp with python 2.7
(f=ur"D:\OneDrive\火山渣颗粒原始数据\火山渣_处理.bmp".encode('gbk')).

I found when I use the command f=r"D:\OneDrive\火山渣颗粒原始数据\火山渣_处理.bmp".encode('gbk')
on python 2.7, the returned f is
b'D:\\OneDrive\\\xbb\xf0\xc9\xbd\xd4\xfc\xbf\xc5\xc1\xa3\xd4\xad\xca\xbc\xca\xfd\xbe\xdd\\\xbb\xf0\xc9\xbd\xd4\xfc_\xb4\xa6\xc0\xed.bmp'

while the return on python 3.5 is
'D:\\OneDrive\\\xbb\xf0\xc9\xbd\xd4\xfc\xbf\xc5\xc1\xa3\xd4\xad\xca\xbc\xca\xfd\xbe\xdd\\\xbb\xf0\xc9\xbd\xd4\xfc_\xb4\xa6\xc0\xed.bmp'.
Maybe the difference raise the problem.

xiejunyi1991 gravatar imagexiejunyi1991 ( 2016-11-26 07:44:43 -0600 )edit

please do not use chinese characters in the 1st place for this.

berak gravatar imageberak ( 2016-11-26 07:58:13 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-26 01:16:32 -0600

Seen: 1,978 times

Last updated: Nov 26 '16