From 7f3430f95dda8bc60e00b07e22c0de6cd9fba760 Mon Sep 17 00:00:00 2001
From: wangzhibo <wangzhibo@shsening.com>
Date: 星期一, 14 三月 2022 15:25:46 +0800
Subject: [PATCH] change countours method
---
debug/1_check_frame_boundary.py | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/debug/1_check_frame_boundary.py b/debug/1_check_frame_boundary.py
index f22b3b4..26b4764 100644
--- a/debug/1_check_frame_boundary.py
+++ b/debug/1_check_frame_boundary.py
@@ -4,26 +4,26 @@
from cv2 import waitKey
import getopt
import sys
-
+from _image_clip_setting import image_clip
def check_frame(frame):
- #image = frame[176:234,280:426]
- image = frame[180:230,250:370] #frame[176:234,280:426]
-
- #cv2.imshow('src',image)
+ image = frame[image_clip[0]:image_clip[1], image_clip[2]:image_clip[3]]
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (6, 6))
counter = cv2.morphologyEx(thresh.copy(), cv2.MORPH_OPEN, kernel)
image_h = image.shape[0]
- contours, hierarchy = cv2.findContours(counter,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_SIMPLE)
+ contours, hierarchy = cv2.findContours(counter,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
+ contours_count = 0
for c in contours:
x, y, w, h = cv2.boundingRect(c)
- if image_h*0.98 > h > image_h * 0.3:
- #print((x, y, w, h))
+ if hierarchy[0][contours_count][3] ==0 :
+ #if image_h*0.98 > h > image_h * 0.6:
+ print((x, y, w, h))
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
+ contours_count += 1
cv2.imshow('frame',image)
waitKey(0)
--
Gitblit v1.9.1