-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurve_detection.py
50 lines (41 loc) · 1.42 KB
/
curve_detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import cv2
import argparse
import numpy as np
import math
def read_image(image_path):
img = cv2.imread(image_path)
if img is None:
raise IOError(f"Image {image_path} not found.")
return img
def intersection(line1, line2):
rho1, theta1 = line1[0]
rho2, theta2 = line2[0]
A = np.array([[np.cos(theta1), np.sin(theta1)], [np.cos(theta2), np.sin(theta2)]])
b = np.array([[rho1], [rho2]])
x0, y0 = np.linalg.solve(A, b)
return int(np.round(x0)), int(np.round(y0))
def segmented_intersections(lines):
intersections = []
for i, group in enumerate(lines[:-1]):
for next_group in lines[i+1:]:
for line1 in group:
for line2 in next_group:
intersections.append(intersection(line1, line2))
return intersections
# Add other functions here (segment_by_angle_kmeans, drawLines)
def main(image_path):
img = read_image(image_path)
og = img.copy()
clean = img.copy()
# Add the code to process the image here
cv2.imshow("Segmented lines", img_with_segmented_lines)
cv2.waitKey()
cv2.imwrite("intersection_points.jpg", img_with_segmented_lines)
cv2.imshow("End result", og)
cv2.waitKey()
cv2.destroyAllWindows()
if __name__ == "__main__":
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(ap.parse_args())
main(args["image"])