Ask Your Question

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

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

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:

How can I solve this problem?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

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

berak gravatar image

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

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


I'm sure opencv 2.4 work well in 2nd examp with python 2.7

I found when I use the command f=r"D:\OneDrive\火山渣颗粒原始数据\火山渣_处理.bmp".encode('gbk')
on python 2.7, the returned f is

while the return on python 3.5 is
Maybe the difference raise the problem.

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

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

berak gravatar imageberak ( 2016-11-26 07:58:13 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 817 times

Last updated: Nov 26 '16