Hey
i just have a short question:
Following code is a loop i created to draw contours with a minimum area of 500px.
Why do i have to keep the print function after the loop active so that the loop function actually processes sth? When i delete the print function in last line its just as the program wouldnt process the loop. This makes sense to me because i only define the loop and dont execute it, but is there an other way to execute the loop than having that print function at the end?
This is just so i can simplify my code, it works as it is.
def contour_areas(contours):
areas = []
for cnt in contours:
cont_area = cv.contourArea(cnt)
if cont_area >= 500:
areas.append(cont_area)
if cont_area >= 500:
cv.drawContours(imgcontours_min_area, contours, -1, (0, 255, 255), 1)
#not minimal rect:
#x,y,w,h = cv.boundingRect(cnt)
#cv.rectangle(imgcontours_min_area,(x,y),(x+w,y+h),(0,0,255),2)
#cv.putText(imgcontours_min_area, "w={},h={}".format(w,h), (x,y - 10), cv.FONT_HERSHEY_SIMPLEX, 0.7, (0,0,255), 2)
rect = cv.minAreaRect(cnt)
box = cv.boxPoints(rect)
box = np.int0(box)
cv.drawContours(imgcontours_min_area,[box],0,(0,0,255),1)
(x, y), (w, h), angle = rect
cv.putText(imgcontours_min_area, "w={},h={}".format(round(w, 2), round(h, 2)), (int(x),int(y-60)), cv.FONT_HERSHEY_SIMPLEX, 0.7, (0,0,255), 2) #x, y in integer sonst falscher data type
return areas
print('Funktion contour_areas vor sortieren:', contour_areas(contours))