Update tempo.txt
Browse files
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 |
-
#
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|