How to solve Threshold Otsu in OpenCV

Viewed 24
squareKern = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))
light = cv2.morphologyEx(gray, cv2.MORPH_CLOSE, squareKern)
light,th1 = cv2.threshold(light, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
cv2.imshow("light",light)
cv2.WaitKey(0)
cv2.destroyAllWindows()

Im getting an error in cv2.THRESH_OTSU:

error: (-2:Unspecified error) in function 'double cv::threshold(cv::InputArray, cv::OutputArray, double, double, int)' THRESH_OTSU mode: 'src_type == CV_8UC1 || src_type == CV_16UC1' where 'src_type' is 24 (CV_8UC4)

0 Answers
Related