Traceback (most recent call last):
File "C:\Users\hereo\OneDrive\바탕 화면\Cube\imgSearch.py", line 52, in <module>
cv2.imshow('test', img)
cv2.error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'imshow'
> Overload resolution failed:
> - mat is not a numerical tuple
> - Expected Ptr<cv::cuda::GpuMat> for argument 'mat'
> - Expected Ptr<cv::UMat> for argument 'mat'
cv2 라이브러리로 이미지를 다루다가 오류가 났다.
def imgPreprocessing(url, v = 127):
cap = cv2.imread(url, cv2.IMREAD_GRAYSCALE)
return cv2.threshold(cap, v, 255, cv2.THRESH_BINARY)
img = imgPreprocessing(imgURL,v=127)
cv2.imshow('test', img)
cv2.waitKey(0)
원인은 cv2.threshold 의 리턴값은 이미지뿐만 아니라 trash 라는 특정 값을 추가로 전달한다. 따라서 해당 코드처럼 img 를 단순히받아서 show를 할 경우 위 오류가 난다.
trash, img = imgPreprocessing(imgURL,v=i)
아래와 같이 수정해주면 된다.