0

I am trying to find the biggest contour in an image which contains 2 contours and one of those are not close line. the contour line is cut from the edge of the image. the other one is close and consist an area.

roi_cnts = sorted(roi_cnts, key = cv2.contourArea, reverse = True)[:1]

is different from

roi_cnts = max(roi_cnts, key=cv2.contourArea)
#or
roi_cnts = sorted(roi_cnts, key = cv2.contourArea, reverse = True)[0]

I don't understand why the two method have different result.

YJJ
  • 45
  • 10

1 Answers1

2

Slice notation [:1] produces a 1-list containing the first element. Key notation [0] produces the first element, but not in a list.

>>> mylist = range (10)
>>> mylist[:1]
[0]
>>> mylist[0]
0
BoarGules
  • 16,440
  • 2
  • 27
  • 44