![](/img/trans.png)
[英]"cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'line'"
[英]cv2.error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'imwrite' img data type = 17 is not supported
我正在嘗試使用圖片來創建直方圖均衡。 我已經導入了圖像和 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)
這些是錯誤的。
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()
失敗。 它返回None
。 找不到文件或文件已損壞。
equalizeHist()
沒有抱怨。 它也只是返回None
。
res
現在變成array([None, None], dtype=object)
imwrite()
無法處理此問題並抱怨此錯誤消息。
解決方法是確保imread()
成功。 弄清楚文件是否確實存在。
assert os.path.exists(path)
img = cv.imread(path)
assert img is not None
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.