-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (41 loc) · 1.61 KB
/
main.py
File metadata and controls
50 lines (41 loc) · 1.61 KB
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 numpy as np
import argparse
import sys
from FL_lib.find_lines import find_lines
from Tests.tests import run_tests
def main():
parser = argparse.ArgumentParser(description="Piece Project CLI")
parser.add_argument("-t", "--tests", action="store_true", help="Run tests")
parser.add_argument("-d", "--debug", action="store_true", help="Enable debug mode with verbose output")
args = parser.parse_args()
if args.tests:
test_params = { 'CANVAS_SIZE': 40,
'LEN_THRESH':10,
'LOG': False,
'debug': args.debug }
passed, total = run_tests(test_params)
return
SIZE = 20
# create a white canvas of size SIZExSIZE
img = np.zeros((SIZE, SIZE,3), dtype=np.uint8)
# draw a line
cv2.line(img, (1,18), (18,1), (255, 255, 255), thickness=1)
# draw line interference
# cv2.line(img, (1,2), (2,1), (255, 255, 255), thickness=1)
lines_found, gray = find_lines(img, len_thresh=10, debug=args.debug)
if not len(lines_found):
print("No lines found.")
else:
print(f"Found {len(lines_found)} lines:")
for line in lines_found:
points, angle = line
print(f"Found line {points[0]} - {points[-1]} with angle: {np.degrees(angle):.1f} degrees")
# SCALE IMAGE TO 500X500
scaled_img = cv2.resize(gray, (500, 500), interpolation=cv2.INTER_NEAREST)
# Display the image
cv2.imshow("Line", scaled_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == "__main__":
main()