-
Notifications
You must be signed in to change notification settings - Fork 0
/
aruco_LET.py
299 lines (254 loc) · 12.5 KB
/
aruco_LET.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import numpy as np
import cv2
import cv2.aruco as aruco
import math
import wget
import ssl
import sys
import urllib
from AppKit import NSSound
from time import sleep
ipold = 'http://192.168.1.2:8080/shot.jpg?rnd=189828'
ipnew = 'http://192.168.1.9:8080/shot.jpg?rnd=436060'
ipxia = 'https://192.168.1.14:8080/shot.jpg?rnd=142522'
ipfab = 'https://172.20.10.13:8080/shot.jpg?rnd=245139'
ipvale = 'https://192.168.43.140:8080/shot.jpg?rnd=94568'
ipnico = 'https://192.168.43.140:8080/shot.jpg?rnd=565089'
def calculateCenters (x1,y1,x2,y2):
c=[]
c.append((x1+x2)/2)
c.append((y1+y2)/2)
return c
def checkdist(x1,y1,x2,y2,distmax=40):
d = math.sqrt(((x1-x2)**2)+((y1-y2)**2))
if d <= distmax:
return 1
else:
return 0
#-------------------------------------------------
'''
NIPOTE
PITONE
TOPINE
'''
#-----------------------------------------------
ssl._create_default_https_context = ssl._create_unverified_context
#wget.download(ipfab)
if sys.version_info[0] == 3:
from urllib.request import urlopen
else:
# Not Python 3 - today, it is most likely to be Python 2
# But note that this might need an update when Python 4
# might be around one day
from urllib import urlopen
#cap = cv2.VideoCapture(0)
while(True):
cap = cv2.VideoCapture(ipfab)
if cap.isOpened():
#print("Device Opened\n")
# Capture frame-by-frame
ret, frame = cap.read()
#print(frame.shape) #480x640
# Our operations on the frame come here
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = frame;
aruco_dict = aruco.Dictionary_get(aruco.DICT_4X4_250)
parameters = aruco.DetectorParameters_create()
#print(parameters)
# ''' detectMarkers(...)
# detectMarkers(image, dictionary[, corners[, ids[, parameters[, rejectedI
# mgPoints]]]]) -> corners, ids, rejectedImgPoints
# '''
#lists of ids and the corners beloning to each id
corners, ids, rejectedImgPoints = aruco.detectMarkers(gray, aruco_dict, parameters=parameters)
#print(corners)
print("\n")
# THE PEN IS ON THE TABLE
# IS THE PEN ON THE TABLE ?
centers = [[],[],[],[],[],[],[]]
cornerID = [[],[],[],[],[],[],[]]
if type(ids) is np.ndarray:
#print(ids.size)
for i in range(ids.size):
if ids[i][0] > 6:
print("Sono un programma di merdaaa!!")
else:
centers[ids[i][0]] = calculateCenters(corners[i][0][0][0], corners[i][0][0][1], corners[i][0][2][0], corners[i][0][2][1])
cornerID[ids[i][0]] = (corners[i][0][0][0], corners[i][0][0][1]), (corners[i][0][1][0], corners[i][0][1][1]), (corners[i][0][2][0], corners[i][0][2][1]),(corners[i][0][3][0], corners[i][0][3][1])
print(ids)
print(cornerID)
#print(ids)
# print(corners[0])
# print(corners[0][0][2])
#It's working.
# my problem was that the cellphone put black all around it. The alrogithm
# depends very much upon finding rectangular black blobs
#print(centers)
gray = aruco.drawDetectedMarkers(gray, corners, borderColor=(255, 0, 0))
sound = NSSound.alloc()
#se vede il marker disegna i centri
# if centers[0]:
# center0 = (int(centers[0][0]), int(centers[0][1]))
# cv2.circle(gray,(center0), 1, (255,0,0), -1)
# #cv2.line(gray,(int(centers[1][0]), int(centers[1][1])),(center0),(255,0,0),5)
# if centers[1]:
# center1 = (int(centers[1][0]), int(centers[1][1]))
# cv2.circle(gray,(center1), 1, (255,0,0), -1)
# if centers[2]:
# center2 = (int(centers[2][0]), int(centers[2][1]))
# cv2.circle(gray,(center2), 1, (255,0,0), -1)
# if centers[3]:
# center0 = (int(centers[3][0]), int(centers[3][1]))
# cv2.circle(gray,(center0), 1, (255,0,0), -1)
# if centers[4]:
# center0 = (int(centers[4][0]), int(centers[4][1]))
# cv2.circle(gray,(center0), 1, (255,0,0), -1)
# if centers[5]:
# center0 = (int(centers[5][0]), int(centers[5][1]))
# cv2.circle(gray,(center0), 1, (255,0,0), -1)
# if centers[6]:
# center0 = (int(centers[6][0]), int(centers[6][1]))
# cv2.circle(gray,(center0), 1, (255,0,0), -1)
# se vede i marker
#-------------------------------------------------------------
'''
NIPOTE 012345
'''
f=0
'''
FAI IL CHECK SULLE INIZIALI DELLE PAROLEEEEEE!!!!
'''
if centers[0] and centers[1] and centers[2] and centers[3] and centers[4] and centers[5]:
# N 0 I 1
if (checkdist(cornerID[0][0][0], cornerID[0][0][1], cornerID[1][1][0], cornerID[1][1][1]) and checkdist(cornerID[0][3][0], cornerID[0][3][1], cornerID[1][2][0], cornerID[1][2][1])):
# font = cv2.FONT_HERSHEY_SIMPLEX
f+=1
# cv2.putText(gray,'yeeee 0-1',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
# I 1 P 2
if checkdist(cornerID[1][0][0], cornerID[1][0][1], cornerID[2][1][0], cornerID[2][1][1]) and checkdist(cornerID[1][3][0], cornerID[1][3][1], cornerID[2][2][0], cornerID[2][2][1]):
# font = cv2.FONT_HERSHEY_SIMPLEX
f+=1
# cv2.putText(gray,'yeeee 1-2',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
#P 2 O 3
if checkdist(cornerID[2][0][0], cornerID[2][0][1], cornerID[3][1][0], cornerID[3][1][1]) and checkdist(cornerID[2][3][0], cornerID[2][3][1], cornerID[3][2][0], cornerID[3][2][1]):
# font = cv2.FONT_HERSHEY_SIMPLEX
f+=1
# cv2.putText(gray,'yeeee 2-3',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
#O 3 T 4
if checkdist(cornerID[3][0][0], cornerID[3][0][1], cornerID[4][1][0], cornerID[4][1][1]) and checkdist(cornerID[3][3][0], cornerID[3][3][1], cornerID[4][2][0], cornerID[4][2][1]):
#font = cv2.FONT_HERSHEY_SIMPLEX
f+=1
# cv2.putText(gray,'yeeee 3-4',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
# T 4 E 5
if checkdist(cornerID[4][0][0], cornerID[4][0][1], cornerID[5][1][0], cornerID[5][1][1]) and checkdist(cornerID[4][3][0], cornerID[4][3][1], cornerID[5][2][0], cornerID[5][2][1]):
#font = cv2.FONT_HERSHEY_SIMPLEX
f+=1
#cv2.putText(gray,'yeeee 4-5',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
if f==5:
# font = cv2.FONT_HERSHEY_SIMPLEX
# cv2.putText(gray,'NIPOTEEE',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
#sleep(0.2)
sound.initWithContentsOfFile_byReference_('/Users/saracolosio/Downloads/sting.wav', True)
sound.play()
sleep(sound.duration())
sleep(1.5)
#break
#-------------------------------------------------------------------------------------------------
'''
PITONE 214305
'''
g=0
if centers[0] and centers[1] and centers[2] and centers[3] and centers[4] and centers[5]:
# p 2 I 1
if (checkdist(cornerID[2][0][0], cornerID[2][0][1], cornerID[1][1][0], cornerID[1][1][1]) and checkdist(cornerID[2][3][0], cornerID[2][3][1], cornerID[1][2][0], cornerID[1][2][1])):
# font = cv2.FONT_HERSHEY_SIMPLEX
g+=1
# cv2.putText(gray,'yeeee 0-1',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
# I 1 t 4
if checkdist(cornerID[1][0][0], cornerID[1][0][1], cornerID[4][1][0], cornerID[4][1][1]) and checkdist(cornerID[1][3][0], cornerID[1][3][1], cornerID[4][2][0], cornerID[4][2][1]):
# font = cv2.FONT_HERSHEY_SIMPLEX
g+=1
# cv2.putText(gray,'yeeee 1-2',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
# t 4 O 3
if checkdist(cornerID[4][0][0], cornerID[4][0][1], cornerID[3][1][0], cornerID[3][1][1]) and checkdist(cornerID[4][3][0], cornerID[4][3][1], cornerID[3][2][0], cornerID[3][2][1]):
# font = cv2.FONT_HERSHEY_SIMPLEX
g+=1
# cv2.putText(gray,'yeeee 2-3',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
#O 3 n 0
if checkdist(cornerID[3][0][0], cornerID[3][0][1], cornerID[0][1][0], cornerID[0][1][1]) and checkdist(cornerID[3][3][0], cornerID[3][3][1], cornerID[0][2][0], cornerID[0][2][1]):
#font = cv2.FONT_HERSHEY_SIMPLEX
g+=1
# cv2.putText(gray,'yeeee 3-4',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
# n 0 E 5
if checkdist(cornerID[0][0][0], cornerID[0][0][1], cornerID[5][1][0], cornerID[5][1][1]) and checkdist(cornerID[0][3][0], cornerID[0][3][1], cornerID[5][2][0], cornerID[5][2][1]):
#font = cv2.FONT_HERSHEY_SIMPLEX
g+=1
#cv2.putText(gray,'yeeee 4-5',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
if g==5:
# font = cv2.FONT_HERSHEY_SIMPLEX
# cv2.putText(gray,'PITONEE',(20,100), font, 1,(0,255,0),3,cv2.LINE_AA)
#sleep(0.2)
sound.initWithContentsOfFile_byReference_('/Users/saracolosio/Downloads/sting.wav', True)
sound.play()
sleep(sound.duration())
sleep(1.5)
#break
#-------------------------------------------------------------
'''
TOPINE 432105
'''
h=0
'''
FAI IL CHECK SULLE INIZIALI DELLE PAROLEEEEEE!!!!
'''
if centers[0] and centers[1] and centers[2] and centers[3] and centers[4] and centers[5]:
# T 4 0 3
if (checkdist(cornerID[4][0][0], cornerID[4][0][1], cornerID[3][1][0], cornerID[3][1][1]) and checkdist(cornerID[4][3][0], cornerID[4][3][1], cornerID[3][2][0], cornerID[3][2][1])):
# font = cv2.FONT_HERSHEY_SIMPLEX
h+=1
# cv2.putText(gray,'yeeee 0-1',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
# 0 3 P 2
if checkdist(cornerID[3][0][0], cornerID[3][0][1], cornerID[2][1][0], cornerID[2][1][1]) and checkdist(cornerID[3][3][0], cornerID[3][3][1], cornerID[2][2][0], cornerID[2][2][1]):
# font = cv2.FONT_HERSHEY_SIMPLEX
h+=1
# cv2.putText(gray,'yeeee 1-2',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
#P 2 I 1
if checkdist(cornerID[2][0][0], cornerID[2][0][1], cornerID[1][1][0], cornerID[1][1][1]) and checkdist(cornerID[2][3][0], cornerID[2][3][1], cornerID[1][2][0], cornerID[1][2][1]):
# font = cv2.FONT_HERSHEY_SIMPLEX
h+=1
# cv2.putText(gray,'yeeee 2-3',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
# I 1 N 0
if checkdist(cornerID[1][0][0], cornerID[1][0][1], cornerID[0][1][0], cornerID[0][1][1]) and checkdist(cornerID[1][3][0], cornerID[1][3][1], cornerID[0][2][0], cornerID[0][2][1]):
#font = cv2.FONT_HERSHEY_SIMPLEX
h+=1
# cv2.putText(gray,'yeeee 3-4',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
# N 0 E 5
if checkdist(cornerID[0][0][0], cornerID[0][0][1], cornerID[5][1][0], cornerID[5][1][1]) and checkdist(cornerID[0][3][0], cornerID[0][3][1], cornerID[5][2][0], cornerID[5][2][1]):
#font = cv2.FONT_HERSHEY_SIMPLEX
h+=1
#cv2.putText(gray,'yeeee 4-5',(20,100), font, 1,(255,255,255),2,cv2.LINE_AA)
if h==5:
# font = cv2.FONT_HERSHEY_SIMPLEX
# cv2.putText(gray,'TOPINEEE',(20,100), font, 1,(0,255,0),3,cv2.LINE_AA)
#sleep(0.2)
sound.initWithContentsOfFile_byReference_('/Users/saracolosio/Downloads/sting.wav', True)
sound.play()
sleep(sound.duration())
sleep(1.5)
#break
#-------------------------------------------------------------------------------------------
'''
PRINTAAAAA
'''
#print(rejectedImgPoints)
# Display the resulting frame
cv2.namedWindow("frame", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("frame",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
print("Failed to open Device\n")
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()