调用OpenCV模块的cvtColor
处理图片:
img_rgb = r'G:\手机照片2022\IMG_122440.jpg'
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
发生了报错,报错内容为:文章来源:https://www.toymoban.com/news/detail-513907.html
[ WARN:0@0.011] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('G:\手机照片2022\IMG_122440.jpg'): can't open/read file: check file path/integrity
Traceback (most recent call last):
File "G:\Test39.py", line 26, in <module>
control_to_sketch(image, to_image)
File "G:Test39.py", line 10, in control_to_sketch
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
报错原因:第1行的警告其实有给出了答案,就是路径问题
,不能打开或读取文件,需要改一下路径(can't open/read file: check file path/integrity
)。
解决方法:文章来源地址https://www.toymoban.com/news/detail-513907.html
- 方法1:把路径中涉及到中文的文件夹的名称改为非中文名称,如:
img_rgb = r'G:\mobile_photo_2022\IMG_122440.jpg'
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
- 方法2:重新建一个英文名称的文件夹,将文件放到该文件夹中测试。
到了这里,关于cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!