当前位置:网站首页>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)
边栏推荐
- 2023 International Conference on Information and Communication Engineering (JCICE 2023)
- number_gets the specified number of decimals
- Flutter learning - the beginning
- Wise Force Deleter强制删除工具
- [cesium] 3D Tileset model is loaded and associated with the model tree
- "Recursion" recursion concept and typical examples
- phone call function
- The mall background management system based on Web design and implementation
- 【过一下15】学习 lstm的一周
- uva1325
猜你喜欢

Structured light 3D reconstruction (1) Striped structured light 3D reconstruction

Wise Force Deleter强制删除工具

MySQL Foundation (1) - Basic Cognition and Operation

Lecture 4 Backpropagation Essays

pycharm中调用Matlab配置:No module named ‘matlab.engine‘; ‘matlab‘ is not a package

vscode+pytorch use experience record (personal record + irregular update)

结构光三维重建(二)线结构光三维重建

Flutter learning three-Flutter basic structure and principle

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

u-boot debugging and positioning means
随机推荐
分布式和集群
How does the Flutter TapGestureRecognizer work
Database experiment five backup and recovery
Machine Learning (2) - Machine Learning Fundamentals
2022 Hangzhou Electric Multi-School 1st Session 01
Cryptography Series: PEM and PKCS7, PKCS8, PKCS12
Transformation 和 Action 常用算子
【解码工具】Bitcoin的一些在线工具
OFDM 十六讲 5 -Discrete Convolution, ISI and ICI on DMT/OFDM Systems
将照片形式的纸质公章转化为电子公章(不需要下载ps)
Basic properties of binary tree + oj problem analysis
Matplotlib(三)—— 实践
Lecture 5 Using pytorch to implement linear regression
1068找到更多的硬币
「PHP8入门指南」PHP简明介绍
多线程查询结果,添加List集合
redis复制机制
The role of the range function
2023年信息与通信工程国际会议(JCICE 2023)
Flutter真机运行及模拟器运行