Browse Source

add circles detecting

jezvgg 11 months ago
parent
commit
4c63333031
1 changed files with 8 additions and 7 deletions
  1. 8 7
      falling_ball/cv.py

+ 8 - 7
falling_ball/cv.py

@@ -15,15 +15,16 @@ def recognize(image):
 
 
     binary[np.any(hsv > 190, axis=2)] = 1
     binary[np.any(hsv > 190, axis=2)] = 1
 
 
-    cv2.imshow('Image', binary)
-
+    contours = cv2.findContours(binary.astype('uint8'), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)[0]
+    for i,contour in enumerate(contours):
+        # print(contour)
+        print(chose(contour))
+        if chose(contour) == 'circle':
+            cv2.drawContours(image, contours, i, (0, 255, 0), 10)
+
+    cv2.imshow('Image', image)
     while cv2.waitKey(1) != ord('q'): continue
     while cv2.waitKey(1) != ord('q'): continue
 
 
-    labels, labeledScreen = cv2.connectedComponents(binary)
-    cnts, hierrache = cv2.findContours(labels, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
-    for label in labels:
-        print(chose(label))
-
     # image = image[t_min_loc1[1] + 20:t_min_loc2[1], t_min_loc1[0] + 20:t_min_loc2[0]]
     # image = image[t_min_loc1[1] + 20:t_min_loc2[1], t_min_loc1[0] + 20:t_min_loc2[0]]
 
 
     # hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
     # hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)