Я хочу получить площадь контуров, которые я вижу в этом изображении/кадре видео:

Проблема в том, что контур обрезан справа, как вы можете видеть, вот почему это так и есть. не распознается как замкнутый контур, и cv2.contourArea() не вернет никакого значения/не распознает это.
Есть ли у кого-нибудь решение, позволяющее обнаружить эту область?
while True:
ret, frame = cap.read()
if not ret:
print("couldnt read video or video has ended!")
break
frame_prob = frame[ystart:yend, xstart:xend]
frame_all_contours = frame_prob.copy()
gray = cv2.cvtColor(frame_prob, cv2.COLOR_BGR2GRAY)
frame_norm = cv2.equalizeHist(gray)
_, mask = cv2.threshold(frame_norm, thresh=10, maxval=255, type= cv2.THRESH_BINARY_INV)
mask = cv2.dilate(mask, kernel, iterations = 2)
edge = cv2.Canny(mask, 90, 250, apertureSize=3)
contours, _ = cv2.findContours(edge, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(frame_all_contours, contours, -1, (0,255,0), 3)
min_area_threshold = 200
filtered_contours = []
for i in contours:
if cv2.contourArea(i) > min_area_threshold:
filtered_contours.append(i)
cv2.drawContours(frame_prob, filtered_contours, -1, (0,255,0), 3)
if filtered_contours:
max_contour = max(filtered_contours, key=cv2.contourArea)
max_areas.append(cv2.contourArea(max_contour))
cv2.drawContours(frame_prob, [max_contour], -1, (0,0,255), 3)
else:
max_areas.append(0)
opt_flow = cv2.calcOpticalFlowFarneback(mask_first, mask, None, 0.5, 3, 30, 3, 5, 1.2, 0)
mask_first = mask
frame_count += 1
cv2.imshow("All contours", frame_all_contours)
cv2.imshow("thresholded contours", frame_prob)
cv2.imshow("Canny mask to detect contours from", edge)
Подробнее здесь: https://stackoverflow.com/questions/798 ... -in-opencv
Мобильная версия