Nekshay commited on
Commit
027370c
·
verified ·
1 Parent(s): 2beace7

Update tempo.txt

Browse files
Files changed (1) hide show
  1. tempo.txt +28 -20
tempo.txt CHANGED
@@ -7,23 +7,31 @@ mask = cv2.imread('mask_image.png', cv2.IMREAD_GRAYSCALE) # Replace 'mask_image
7
  # Apply Gaussian blur to the image to reduce noise
8
  blurred = cv2.GaussianBlur(mask, (5, 5), 0)
9
 
10
- # Apply Hough Circle Transform to detect circles
11
- circles = cv2.HoughCircles(blurred, cv2.HOUGH_GRADIENT, dp=1, minDist=20, param1=50, param2=30, minRadius=0, maxRadius=0)
12
-
13
- if circles is not None:
14
- circles = np.uint16(np.around(circles))
15
-
16
- # Filter out semicircles based on the position of the circle centers
17
- semicircles = [circle[0] for circle in circles[0] if circle[1] < mask.shape[0] / 2]
18
-
19
- # Draw the semicircles on a blank image
20
- semicircle_image = np.zeros_like(mask)
21
- for (x, y, r) in semicircles:
22
- cv2.circle(semicircle_image, (x, y), r, (255, 255, 255), thickness=cv2.FILLED)
23
-
24
- # Display the image with the semicircles
25
- cv2.imshow('Semicircles in Mask', semicircle_image)
26
- cv2.waitKey(0)
27
- cv2.destroyAllWindows()
28
- else:
29
- print("No semicircles found in the image.")
 
 
 
 
 
 
 
 
 
7
  # Apply Gaussian blur to the image to reduce noise
8
  blurred = cv2.GaussianBlur(mask, (5, 5), 0)
9
 
10
+ # Detect edges using Canny edge detection
11
+ edges = cv2.Canny(blurred, threshold1=50, threshold2=150)
12
+
13
+ # Find contours in the edge-detected image
14
+ contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
15
+
16
+ # Initialize an empty list to store half ellipses
17
+ half_ellipses = []
18
+
19
+ # Iterate through the contours
20
+ for contour in contours:
21
+ # Fit an ellipse to the contour
22
+ if len(contour) >= 5:
23
+ ellipse = cv2.fitEllipse(contour)
24
+
25
+ # Check if the angle of the fitted ellipse is close to 180 degrees (half ellipse)
26
+ if 170 < ellipse[2] < 190:
27
+ half_ellipses.append(ellipse)
28
+
29
+ # Draw the detected half ellipses on a blank image
30
+ half_ellipse_image = np.zeros_like(mask)
31
+ for ellipse in half_ellipses:
32
+ cv2.ellipse(half_ellipse_image, ellipse, (255, 255, 255), thickness=cv2.FILLED)
33
+
34
+ # Display the image with the detected half ellipses
35
+ cv2.imshow('Half Ellipses in Mask', half_ellipse_image)
36
+ cv2.waitKey(0)
37
+ cv2.destroyAllWindows()