Update tempo.txt
Browse files
tempo.txt
CHANGED
|
@@ -1,43 +1,61 @@
|
|
| 1 |
import cv2
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
#
|
| 11 |
-
|
| 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 |
-
#
|
| 19 |
-
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
if
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import cv2
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
+
def extend_line_to_image_edges(x1, y1, x2, y2, img_width, img_height):
|
| 5 |
+
# Calculate the slope (m) and intercept (c) of the line
|
| 6 |
+
if x2 != x1:
|
| 7 |
+
m = (y2 - y1) / (x2 - x1)
|
| 8 |
+
c = y1 - m * x1
|
| 9 |
+
else:
|
| 10 |
+
# The line is vertical
|
| 11 |
+
m = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# Find intersection points with image borders
|
| 14 |
+
points = []
|
| 15 |
|
| 16 |
+
# Intersection with the left border (x=0)
|
| 17 |
+
if m is not None:
|
| 18 |
+
y_at_left = c
|
| 19 |
+
if 0 <= y_at_left <= img_height:
|
| 20 |
+
points.append((0, int(y_at_left)))
|
| 21 |
+
|
| 22 |
+
# Intersection with the right border (x=img_width)
|
| 23 |
+
if m is not None:
|
| 24 |
+
y_at_right = m * img_width + c
|
| 25 |
+
if 0 <= y_at_right <= img_height:
|
| 26 |
+
points.append((img_width, int(y_at_right)))
|
| 27 |
+
|
| 28 |
+
# Intersection with the top border (y=0)
|
| 29 |
+
if m is not None:
|
| 30 |
+
x_at_top = -c / m
|
| 31 |
+
if 0 <= x_at_top <= img_width:
|
| 32 |
+
points.append((int(x_at_top), 0))
|
| 33 |
+
else:
|
| 34 |
+
# The line is vertical and intersects the top border if y1=0 or y2=0
|
| 35 |
+
if y1 == 0:
|
| 36 |
+
points.append((x1, 0))
|
| 37 |
+
elif y2 == 0:
|
| 38 |
+
points.append((x2, 0))
|
| 39 |
+
|
| 40 |
+
# Intersection with the bottom border (y=img_height)
|
| 41 |
+
if m is not None:
|
| 42 |
+
x_at_bottom = (img_height - c) / m
|
| 43 |
+
if 0 <= x_at_bottom <= img_width:
|
| 44 |
+
points.append((int(x_at_bottom), img_height))
|
| 45 |
+
else:
|
| 46 |
+
# The line is vertical and intersects the bottom border if y1=img_height or y2=img_height
|
| 47 |
+
if y1 == img_height:
|
| 48 |
+
points.append((x1, img_height))
|
| 49 |
+
elif y2 == img_height:
|
| 50 |
+
points.append((x2, img_height))
|
| 51 |
+
|
| 52 |
+
# Choose the two valid intersection points that extend the line
|
| 53 |
+
if len(points) >= 2:
|
| 54 |
+
extended_points = points[:2]
|
| 55 |
+
else:
|
| 56 |
+
extended_points = points
|
| 57 |
+
|
| 58 |
+
return extended_points
|
| 59 |
+
|
| 60 |
+
# Example usage
|
| 61 |
+
img = np.zeros((500, 500, 3),
|