For those who want an OpenCV solution, here it is:
ret,thresh = cv2.threshold(image,245,255,0) contours, hierarchy = cv2.findContours(thresh,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE) tam = 0 for contorno in contours: if len(contorno) > tam: contornoGrande = contorno tam = len(contorno) cv2.drawContours(image,contornoGrande.astype('int'),-1,(0,255,0),2) cv2.imshow('My image',image) cv2.waitKey() cv2.destroyAllWindows()
In this example, I draw the largest outline. Remember that the "image" must be a single-channel array.
You have to change the parameters of the threshold function, the findContours function and the drawContours function to get what you want.
I am doing a conversion to 'int' in the drawContours function because there is an error in Open CV 2.4.3, and if you do not perform this conversion, the program is interrupted. This is a mistake .
Xithias
source share