当前位置:网站首页>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)
边栏推荐
- Mesos学习
- Transformation 和 Action 常用算子
- uva1325
- A blog clears the Redis technology stack
- redis 缓存清除策略
- jvm three heap and stack
- 第四讲 back propagation 反向传播
- 1.3 mysql batch insert data
- Structured Light 3D Reconstruction (2) Line Structured Light 3D Reconstruction
- Distributed systems revisited: there will never be a perfect consistency scheme...
猜你喜欢

A blog clears the Redis technology stack

SQL(二) —— join窗口函数视图

Structured Light 3D Reconstruction (2) Line Structured Light 3D Reconstruction

DOM and its applications

Matplotlib(三)—— 实践

Excel Paint

【过一下 17】pytorch 改写 keras

Error creating bean with name 'configDataContextRefresher' defined in class path resource

第四讲 反向传播随笔

【cesium】Load and locate 3D Tileset
随机推荐
第二讲 Linear Model 线性模型
Flutter learning 5-integration-packaging-publish
『递归』递归概念与典型实例
2022杭电多校第一场01
学习总结week3_2函数进阶
UVA10827
server disk array
CAP+BASE
NodeJs接收上传文件并自定义保存路径
数据库实验五 备份与恢复
pycharm中调用Matlab配置:No module named ‘matlab.engine‘; ‘matlab‘ is not a package
2023年信息与通信工程国际会议(JCICE 2023)
The software design experiment four bridge model experiment
[cesium] 3D Tileset model is loaded and associated with the model tree
Qt制作18帧丘比特表白意中人、是你的丘比特嘛!!!
Flutter learning - the beginning
[cesium] element highlighting
u-boot debugging and positioning means
Analysis of Mvi Architecture
02.01-----参数的引用的作用“ & ”