[英]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.