【错误一】
调用代码为: import cv2 image = cv2.imread("E:\190307_pydemo\0515\02.png") gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) 错误提示为:gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(3.4.2) c:\projects\opencv-python\opencv\modules\imgproc\src\color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'cv::CvtHelper<struct cv::Set<3,4,-1>,struct cv::Set<1,-1,-1>,struct cv::Set<0,2,5>,2>::CvtHelper'
修改方法:在image = cv2.imread("E:\190307_pydemo\0515\02.png")路径前加r。即image = cv2.imread(r"E:\190307_pydemo\0515\02.png")
【错误二】
调用代码为: import cv2 image = cv2.imread(r"E:\190307_pydemo\图片\02.png") gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) 错误提示为:gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(3.4.2) c:\projects\opencv-python\opencv\modules\imgproc\src\color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'cv::CvtHelper<struct cv::Set<3,4,-1>,struct cv::Set<1,-1,-1>,struct cv::Set<0,2,5>,2>::CvtHelper'
修改方法:图片路径中不能含中文文件夹,将图片保存在不含中文的路径中,例如image = cv2.imread(r"E:\190307_pydemo\0515\02.png")
【错误三】
调用代码为: import cv2 image = cv2.imread(r"E:\190307_pydemo\图片\02.png",0) gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) 错误提示为:gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(3.4.2) c:\projects\opencv-python\opencv\modules\imgproc\src\color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function 'cv::CvtHelper<struct cv::Set<3,4,-1>,struct cv::Set<1,-1,-1>,struct cv::Set<0,2,5>,2>::CvtHelper'
修改方法:cv2.imread路径后加 “,0” 时已经将图片读取为灰度图,故转换时报错。此处将image = cv2.imread(r"E:\190307_pydemo\图片\02.png",0)修改为image = cv2.imread(r"E:\190307_pydemo\图片\02.png")即可。因此,以后要注意在做图像灰度变换前,最好先判断确定待变换图像不是灰度图。