当前位置:网站首页>In Opencv, imag=cv2.cvtColor(imag,cv2.COLOR_BGR2GRAY) error: error:!_src.empty() in function 'cv::cvtColor'
In Opencv, imag=cv2.cvtColor(imag,cv2.COLOR_BGR2GRAY) error: error:!_src.empty() in function 'cv::cvtColor'
2022-08-05 05:24:00 【When you are full, you will be strong】
Opencv,imag=cv2.cvtColor(imag,cv2.COLOR_BGR2GRAY) 报错:error:!_src.empty() in function ‘cv::cvtColor’
熟练使用Ctrl+C和Ctrl+V大法后
import cv2
path=r"296059.png"
imag=cv2.imdecode(np.fromfile(path),-1)
imag=cv2.cvtColor(imag,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.图片路径错误,Maybe the image path does not exist
2.To write image suffix
3.There is a Chinese path in the picture
If the above reasons are excluded,可以尝试以下方法:
解决方法1:
Images are divided into single-channel and multi-channel
单通道图像,直接cv2.imread(path, 0)Read in single channel mode.
import cv2
path=r"296059.png"
imag=cv2.imdecode(np.fromfile(path),-1)
imag=cv2.imread(path,0)
解决方法2:
解决方案来源于(-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor‘
#读取图片
import cv2
imag = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 1)
imag = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), -1) # 读入完整图片,见下面解释
imag = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 0) # 读成灰度
imag = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 1) # 读成彩图
在cv2.imdecode中补充:dtype=np.uint8,
如下解决:
import cv2
path=r"296059.png"
imag=cv2.imdecode(np.fromfile(path,dtype=np.uint8),1)
imag=cv2.cvtColor(imag,cv2.COLOR_BGR2GRAY)
边栏推荐
- vscode+pytorch使用经验记录(个人记录+不定时更新)
- Structured Light 3D Reconstruction (2) Line Structured Light 3D Reconstruction
- Transformation 和 Action 常用算子
- SQL(一) —— 增删改查
- redis事务
- flex布局青蛙游戏通关攻略
- 02.01-----参数的引用的作用“ & ”
- After controlling the export file in MySQL, it becomes \N. Is there any solution?
- Flutter learning three-Flutter basic structure and principle
- Qt制作18帧丘比特表白意中人、是你的丘比特嘛!!!
猜你喜欢
随机推荐
位运算符与逻辑运算符的区别
Flutter Learning 4 - Basic UI Components
【过一下11】随机森林和特征工程
[WeChat applet] WXML template syntax - conditional rendering
【过一下 17】pytorch 改写 keras
机器学习(二) —— 机器学习基础
Geek卸载工具
【技能】长期更新
span标签和p标签的区别
有用番茄来监督自己的同道中人吗?加一下我的自习室,一起加油
NodeJs接收上传文件并自定义保存路径
SQL(二) —— join窗口函数视图
【过一下3】卷积&图像噪音&边缘&纹理
2022杭电多校第一场01
Flex layout frog game clearance strategy
What are the characteristics of the interface of the physical layer?What does each contain?
【记一下1】2022年6月29日 哥和弟 双重痛苦
Xiaobai, you big bulls are lightly abused
MySQL Foundation (1) - Basic Cognition and Operation
HQL语句执行过程









