Skip to content

Instantly share code, notes, and snippets.

@guilhermemauro
Created March 1, 2017 19:38
Show Gist options
  • Save guilhermemauro/abdcdb280a475f98f472641c2d822d0d to your computer and use it in GitHub Desktop.
Save guilhermemauro/abdcdb280a475f98f472641c2d822d0d to your computer and use it in GitHub Desktop.
#like the function's name, choose the biggest contour in mask
def findBiggestContour(mask):
temp_bigger = []
img1, cont, hier = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
if len(cont) == 0:
return False
for cnt in cont:
temp_bigger.append(cv2.contourArea(cnt))
greatest = max(temp_bigger)
index_big = temp_bigger.index(greatest)
key = 0
for cnt in cont:
if key == index_big:
return cnt
break
key += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment