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.
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. It returned None
. The file could not be found or the file is corrupt.
equalizeHist()
does not complain. It simply returns None
too.
res
now becomes array([None, None], dtype=object)
imwrite()
can't handle this and complains with this error message.
The fix is to make sure imread()
succeeds. Figure out if the file actually exists.
assert os.path.exists(path)
img = cv.imread(path)
assert img is not None
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.