Update tempo.txt
Browse files
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 |
-
#
|
| 8 |
-
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
|
| 13 |
-
#
|
| 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 |
-
#
|
| 22 |
-
if
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.")
|