python的三方库pylibtiff不支持打开中文路径的图片怎么办
在使用open指令打开图片的时候路径里边的中文乱码,路径没有中文的时候可以正常打开文件。
def open(cls, filename, mode='r'):
""" Open tiff file as TIFF.
"""
try:
try:
# Python3: it needs bytes for the arguments of type "c_char_p"
filename = os.fsencode(filename) # no-op if already bytes
except AttributeError:
# Python2: it needs str for the arguments of type "c_char_p"
if isinstance(filename, unicode): # noqa: F821
filename = filename.encode(sys.getfilesystemencoding())
except Exception as ex:
# It's probably going to not work, but let it try
print('Warning: filename argument is of wrong type or encoding: %s'
% ex)
tiff = libtiff.TIFFOpen(filename, mode.encode('ascii'))
if tiff.value is None:
raise TypeError('Failed to open file ' + repr(filename))
return tiff
numpy支持中文路径,你先把图片用numpy以二进制读取进去,让后用open cv去解码,具体操作你可以搜一下。
你的pycharm的编码格式设置的是utf-8的吗