-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovementhandler.py
107 lines (82 loc) · 2.63 KB
/
movementhandler.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import cv2
import numpy
def writepath(path,image):
currentpos = 1
output_image = image # variable selection
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 0.1
font_color = (0,255,0)
line_type = 2
for x in path: # numbering the path
# y_axis = x[0]*10 + 5
# x_axis = x[1]*10 + 5
# text = str(currentpos)
# cv2.putText(output_image,text,(x_axis,y_axis),font, font_scale,font_color,line_type) # TO DO: Arrows instead of text
writearrow(x, path, output_image)
currentpos +=1
# TO DO: image scaling before outputing on the screencv2.reSize to full resolution
output_image = cv2.resize(output_image, None, fx = 4, fy = 4, interpolation = cv2.INTER_CUBIC)
cv2.imshow('image', output_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
return
# if you can avoid the code bellow this point please do
# The code written there is an abomination, not even the Devil himself wouldn't force somebody to read it
# If the code stops working for some reason, sacrifice a goat to the Cthulhu and ask for help
def finddirection(field1,field2):
if (field1[0] > field2[0]):
return "left"
elif (field1[0] < field2[0]):
return "rigth"
if (field1[1] > field2[1]):
return "up"
elif (field1[1] < field2[1]):
return "down"
else:
return
def setup_field1(field,direction):
if (direction == "up"):
x = field[0]*10 + 5
y = field[1]*10 + 5
elif (direction == "down"):
x = field[0]*10 + 5
y = field[1]*10 + 5
elif (direction == "left"):
x = field[0]*10 + 5
y = field[1]*10 + 5
elif (direction == "rigth"):
x = field[0]*10 + 5
y = field[1]*10 + 5
else:
return
position = (y,x)
return position
def setup_field2(field, direction):
if (direction == "up"):
x = field[0]*10 + 5
y = field[1]*10
elif (direction == "down"):
x = field[0]*10 + 5
y = field[1]*10 + 5
elif (direction == "left"):
x = field[0]*10 + 5
y = field[1]*10 + 5
elif (direction == "rigth"):
x = field[0]*10 + 5
y = field[1]*10 + 5
else:
return
position = (y,x)
return position
def writearrow(field,path,image):
x = field
if (path.index(field) + 1 == len(path)):
return
else:
y = path[path.index(field) + 1]
COLOR = (255,0,0)
THICK = 1
LINE_TYPE = 8
SHIFT = 0
TIP_LENGTH = 0.25
cv2.arrowedLine(image, setup_field1(x, finddirection(x, y)), setup_field2(y, finddirection(x, y)), COLOR, THICK, LINE_TYPE, SHIFT, TIP_LENGTH)