cv2的python版本中无法生成带有中文路径的图片的问题

Posted by Xiphoray on Nov 5, 2017

用以下方法代替

	# python3版本
	# imread

	path_file = "sample"
	img = cv2.imdecode(np.fromfile(path_file,dtype=np.uint8),-1)

	#imwrite
	_path = "sample"
	cv2.imencode('.jpg',img)[1].tofile(_path)
	
	
	# python 2版本
	import cv2
	import sys
	reload(sys)
	sys.setdefaultencoding('u8')
	path_file = u"sample"
	img = cv2.imread(path_file.decode('u8').encode('gbk'),-1)



Share