-1

I was trying to use the contours of and image, and when I tried the following it gave and error. I know for sure that it is because of the 24, because I used another number such as 45 and it would accept it. The rest of the code is okay, that's why I didn't write it.

ret, thresh = cv2.threshold(angray, 251 , 190,  24)

The error is the following one

error: (-215:Assertion failed) automatic_thresh != (CV_THRESH_OTSU | CV_THRESH_TRIANGLE) in function 'cv::threshold'

And the full code just in case you guys want to see it is this one:

import cv2
ancolor = cv2.imread("Anonymous.jpg")
angray = cv2.cvtColor(ancolor, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(angray, 251 , 190,  24)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
print("Number of contours" + str(len(contours)))
cv2.drawContours(ancolor, contours, -1, (0, 255, 0), 3)
cv2.imshow("AnColor", ancolor)
cv2.imshow("AnGray", angray)
cv2.waitKey()

Thanks a lot, first time asking a question on StackOverflow. Thanks.

1 Answers1

1

according to https://docs.opencv.org/3.4.3/d7/d1b/group__imgproc__misc.html#gae8a4a146d1ca78c626a53577199e9c57

retval, dst = cv.threshold(src, thresh, maxval, type[, dst])

I'm not sure what you want to do by ret, thresh = cv2.threshold(angray, 251 , 190, 24)
But 24 is not a valid type argument

Yuan
  • 41
  • 3