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

Update tempo.txt

Browse files
Files changed (1) hide show
  1. tempo.txt +34 -28
tempo.txt CHANGED
@@ -4,34 +4,40 @@ import numpy as np
4
  # Load the mask image
5
  mask = cv2.imread('mask_image.png', cv2.IMREAD_GRAYSCALE) # Replace 'mask_image.png' with the path to your mask image
6
 
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()
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  # Load the mask image
5
  mask = cv2.imread('mask_image.png', cv2.IMREAD_GRAYSCALE) # Replace 'mask_image.png' with the path to your mask image
6
 
7
+ # Find contours in the mask
8
+ contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
9
 
10
+ # Initialize variables to store the last two bottom-right points
11
+ last_two_points = []
12
 
13
+ # Iterate through each contour
 
 
 
 
 
 
14
  for contour in contours:
15
+ # Extract the bottom-right points of the contour
16
+ bottom_right_points = [point[0] for point in contour if point[0][0] == max(contour[:, :, 0]) and point[0][1] == max(contour[:, :, 1])]
17
+
18
+ # Sort the bottom-right points based on their x-coordinate
19
+ bottom_right_points.sort(key=lambda point: point[0])
20
+
21
+ # Choose the last two points
22
+ if len(bottom_right_points) >= 2:
23
+ last_two_points.extend(bottom_right_points[-2:])
24
+
25
+ # Check if the distance between the last two points is more than 200 pixels
26
+ if len(last_two_points) == 2 and np.linalg.norm(np.array(last_two_points[0]) - np.array(last_two_points[1])) > 200:
27
+ # Fit a line passing through the last two points
28
+ vx, vy, x0, y0 = cv2.fitLine(np.array(last_two_points), cv2.DIST_L2, 0, 0.01, 0.01)
29
+
30
+ # Calculate the start and end points of the line
31
+ start_point = (int(x0 - 1000*vx), int(y0 - 1000*vy))
32
+ end_point = (int(x0 + 1000*vx), int(y0 + 1000*vy))
33
+
34
+ # Draw the line on a blank image
35
+ line_image = np.zeros_like(mask)
36
+ cv2.line(line_image, start_point, end_point, (255, 255, 255), thickness=2)
37
+
38
+ # Display the line image
39
+ cv2.imshow('Line Passing Through Last Two Points', line_image)
40
+ cv2.waitKey(0)
41
+ cv2.destroyAllWindows()
42
+ else:
43
+ print("Unable to find suitable points or distance constraint not met.")