【Python】opencv-python读取路径中含中文的图片

【Python】opencv-python读取路径中含中文的图片,第1张

原代码:

img_init = cv2.imread(img_path)
img_init = cv2.resize(img_init, (224, 224))
img = np.asarray(img_init)

错误信息:

cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-q3d_8t8e\opencv\modules\imgproc\src\resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function ‘cv::resize’

原因:图片路径中包含中文

解决方案:

img_init = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), cv2.IMREAD_UNCHANGED)
img_init = cv2.resize(img_init, (224, 224))
img = np.asarray(img_init)

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/922562.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-16
下一篇 2022-05-16

发表评论

登录后才能评论

评论列表(0条)

保存