当前位置:网站首页>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)
边栏推荐
- Xiaobai, you big bulls are lightly abused
- [Student Graduation Project] Design and Implementation of the Website Based on the Web Student Information Management System (13 pages)
- server disk array
- 【过一下14】自习室的一天
- LAB Semaphore Implementation Details
- Flutter真机运行及模拟器运行
- 【微信小程序】WXML模板语法-条件渲染
- 2022杭电多校第一场01
- Flutter learning 2-dart learning
- 【过一下3】卷积&图像噪音&边缘&纹理
猜你喜欢
Dephi reverse tool Dede exports function name MAP and imports it into IDA
A blog clears the Redis technology stack
【过一下10】sklearn使用记录
Develop a highly fault-tolerant distributed system
day10-字符串作业
OFDM 十六讲 5 -Discrete Convolution, ISI and ICI on DMT/OFDM Systems
vscode+pytorch使用经验记录(个人记录+不定时更新)
2022杭电多校第一场01
Flutter learning 5-integration-packaging-publish
SQL(一) —— 增删改查
随机推荐
What field type of MySQL database table has the largest storage length?
第四讲 反向传播随笔
结构光三维重建(二)线结构光三维重建
redis 持久化
redis cache clearing strategy
uboot enable debug printing information
入口点注入
【练一下1】糖尿病遗传风险检测挑战赛 【讯飞开放平台】
Xiaobai, you big bulls are lightly abused
Qt制作18帧丘比特表白意中人、是你的丘比特嘛!!!
【过一下10】sklearn使用记录
开发一套高容错分布式系统
【过一下7】全连接神经网络视频第一节的笔记
Requests库部署与常用函数讲解
Lecture 2 Linear Model Linear Model
Pycharm中使用pip安装第三方库安装失败:“Non-zero exit code (2)“的解决方法
结构光三维重建(一)条纹结构光三维重建
DOM及其应用
Wise Force Deleter强制删除工具
[Software Exam System Architect] Software Architecture Design ③ Domain-Specific Software Architecture (DSSA)