-2

My problem is about creating a list from a loop. As you can see in my code, I am trying to add areas that I found from image to list for creating a list for areas. I cant see what is the problem in code btw it always print NONE

for cnt in contours :

    M = cv2.moments(cnt)

    cx = int(M["m10"] / M["m00"])
    cy = int(M["m01"] / M["m00"])  
    center = (cx,cy)

    area = cv2.contourArea(cnt)
    perimeter = cv2.arcLength(cnt , True)
    x = list_area.append(area)

print (x) 

1 Answers1

1

From what I can understand, without the rest of your code, what you want is:

list_area = []
for cnt in contours :

    M = cv2.moments(cnt)

    cx = int(M["m10"] / M["m00"])
    cy = int(M["m01"] / M["m00"])  
    center = (cx,cy)

    area = cv2.contourArea(cnt)
    perimeter = cv2.arcLength(cnt , True)
    list_area.append(area)

print (list_area) 

This will append values to your list, list_area, and print the full list at the end.

db702
  • 559
  • 4
  • 12