简体   繁体   English

cv2.error: OpenCV(4.7.0):-1: 错误: (-5:Bad argument) in function 'imwrite' img data type = 17 is not supported

[英]cv2.error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'imwrite' img data type = 17 is not supported

I'm trying to use a picture to create a Histograms Equalization.我正在尝试使用图片来创建直方图均衡。 I'm imported image and cv2 already but there are still having an issue.我已经导入了图像和 cv2,但仍然存在问题。

import numpy as np
import cv2 as cv



path = r'C:\Users\Lilly\Downloads\lena_color.jpg'
img = cv.imread(path,0)
equ = cv.equalizeHist(img)
res = np.hstack((img,equ)) 
cv.imwrite('res.png',res)

These is an error.这些是错误的。

PS C:\Users\Lilly> & C:/Users/Lilly/AppData/Local/Programs/Python/Python39/python.exe c:/Users/Lilly/Downloads/Equalization.py
Traceback (most recent call last):
  File "c:\Users\Lilly\Downloads\Equalization.py", line 17, in <module>
    cv.imwrite('res.png',res)
cv2.error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'imwrite'
> Overload resolution failed:
>  - img data type = 17 is not supported
>  - Expected Ptr<cv::UMat> for argument 'img'

imread() failed. imread()失败。 It returned None .它返回None The file could not be found or the file is corrupt.找不到文件或文件已损坏。

equalizeHist() does not complain. equalizeHist()没有抱怨。 It simply returns None too.它也只是返回None

res now becomes array([None, None], dtype=object) res现在变成array([None, None], dtype=object)

imwrite() can't handle this and complains with this error message. imwrite()无法处理此问题并抱怨此错误消息。

The fix is to make sure imread() succeeds.解决方法是确保imread()成功。 Figure out if the file actually exists.弄清楚文件是否确实存在。

assert os.path.exists(path)
img = cv.imread(path)
assert img is not None

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “cv2.error:OpenCV(4.5.5):-1:错误:(-5:错误参数)在函数&#39;line&#39;中” - "cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'line'" cv2.error: OpenCV(4.5.2) 👎 错误: (-5:Bad argument) in function &#39;cvtColor&#39; - cv2.error: OpenCV(4.5.2) 👎 error: (-5:Bad argument) in function 'cvtColor' cv2.error: OpenCV(4.5.4):-1: error: (-5:Bad argument) in function 'warpPerspective' - cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'warpPerspective' cv2.error: opencv(4.5.3):-1: 错误: (-5:bad argument) in function 'resize' - cv2.error: opencv(4.5.3) :-1: error: (-5:bad argument) in function 'resize' cv2.error:OpenCV(4.6.0):-1:错误:(-5:错误参数) - cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) 如何解决“cv2.error: OpenCV(4.5.4):-1: error: (-5:Bad argument) in function 'imshow'” - How to solve "cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'imshow'" Cv2.error : (-215:Assertion failed) !_img.empty() in function &#39;imwrite&#39; - Cv2.error : (-215:Assertion failed) !_img.empty() in function 'imwrite' OpenCV(4.2.0),imwrite() 到子文件夹会破坏模块; cv2.error: (-215:Assertion failed).ssize:empty() in function 'cv::resize'`' - OpenCV(4.2.0),imwrite() to a subfolder breaks the module; cv2.error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'`' 错误OpenCV(4.6.0):-1:错误:(-5:错误参数)在函数&#39;imwrite&#39;中 - error OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'imwrite' OpenCV 4.4.0 错误:(-215:断言失败)._img:empty() 在 function 'cv::imwrite' - OpenCV 4.4.0 error: (-215:Assertion failed) !_img.empty() in function 'cv::imwrite'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM