-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuntitled0.py
88 lines (77 loc) · 4.01 KB
/
untitled0.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
import pupil_apriltags as apriltag
import cv2
import numpy as np
import time
from pupil_apriltags import Detector
cap = cv2.VideoCapture(0)
cv2.namedWindow('camera', cv2.WINDOW_AUTOSIZE)
detector1 = apriltag.Detector(families='tag36h11')
#detector2 = apriltag.Detector(families='tag16h5')
#detector3 = apriltag.Detector(families='tag25h9')
while (1):
ret, image = cap.read()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#options = apriltag.DetectorOptions(families='tag36h11')
tag36h11_tag0=0
tag36h11_tag1=0
tag36h11_tag24=0
tag36h11_tag25=0
results1 = detector1.detect(gray)
#print(results1)
for tag in results1:
if(tag.tag_id==0):
cv2.circle(image, tuple(tag.corners[0].astype(int)), 4,(255,255,255), 2)
cv2.circle(image, tuple(tag.corners[1].astype(int)), 4,(255,255,255), 2)
cv2.circle(image, tuple(tag.corners[2].astype(int)), 4,(255,255,255), 2)
cv2.circle(image, tuple(tag.corners[3].astype(int)), 4,(255,255,255), 2)
if(tag.tag_id==1):
cv2.circle(image, tuple(tag.corners[0].astype(int)), 4,(225,105,65), 2)
cv2.circle(image, tuple(tag.corners[1].astype(int)), 4,(225,105,65), 2)
cv2.circle(image, tuple(tag.corners[2].astype(int)), 4,(225,105,65), 2)
cv2.circle(image, tuple(tag.corners[3].astype(int)), 4,(225,105,65), 2)
if(tag.tag_id==2):
cv2.circle(image, tuple(tag.corners[0].astype(int)), 4,(18,153,255), 2)
cv2.circle(image, tuple(tag.corners[1].astype(int)), 4,(18,153,255), 2)
cv2.circle(image, tuple(tag.corners[2].astype(int)), 4,(18,153,255), 2)
cv2.circle(image, tuple(tag.corners[3].astype(int)), 4,(18,153,255), 2)
if(tag.tag_id==3):
cv2.circle(image, tuple(tag.corners[0].astype(int)), 4,(0,255,127), 2)
cv2.circle(image, tuple(tag.corners[1].astype(int)), 4,(0,255,127), 2)
cv2.circle(image, tuple(tag.corners[2].astype(int)), 4,(0,255,127), 2)
cv2.circle(image, tuple(tag.corners[3].astype(int)), 4,(0,255,127), 2)
if(tag.tag_id==4):
cv2.circle(image, tuple(tag.corners[0].astype(int)), 4,(0,0,255), 2)
cv2.circle(image, tuple(tag.corners[1].astype(int)), 4,(0,0,255), 2)
cv2.circle(image, tuple(tag.corners[2].astype(int)), 4,(0,0,255), 2)
cv2.circle(image, tuple(tag.corners[3].astype(int)), 4,(0,0,255), 2)
if(tag.tag_id==5):
cv2.circle(image, tuple(tag.corners[0].astype(int)), 4,(0,255,255), 2)
cv2.circle(image, tuple(tag.corners[1].astype(int)), 4,(0,255,255), 2)
cv2.circle(image, tuple(tag.corners[2].astype(int)), 4,(0,255,255), 2)
cv2.circle(image, tuple(tag.corners[3].astype(int)), 4,(0,255,255), 2)
#print(tag.tag_id)
#results2 = detector2.detect(gray)
#print(results2)
#for tag in results2:
#cv2.circle(image, tuple(tag.corners[0].astype(int)), 4,(0,255,255), 2) # right-bottom
#cv2.circle(image,tuple(tag.corners[1].astype(int)), 4,(0,255,255), 2) # left-top
#cv2.circle(image, tuple(tag.corners[2].astype(int)), 4,(0,255,255), 2) # right-top
#cv2.circle(image, tuple(tag.corners[3].astype(int)), 4,(0,255,255), 2) # left-bottom
#results3 = detector3.detect(gray)
#print(results3)
#for tag in results3:
#cv2.circle(image, tuple(tag.corners[0].astype(int)), 4,(255,0,255), 2) # right-bottom
#cv2.circle(image,tuple(tag.corners[1].astype(int)), 4,(255,0,255), 2) # left-top
#cv2.circle(image, tuple(tag.corners[2].astype(int)), 4,(255,0,255), 2) # right-top
#cv2.circle(image, tuple(tag.corners[3].astype(int)), 4,(255,0,255), 2) # left-bottom
cv2.imshow('camera', image)
cv2.waitKey(1)
#print('tag0:',tag36h11_tag0,'\n')
#print('tag1:',tag36h11_tag1,'\n')
#print('tag24:',tag36h11_tag24,'\n')
#print('tag25:',tag36h11_tag25,'\n')
#print('\n')
#time.sleep(1.0)
cap.release()
cv2.waitKey(0)
cv2.destroyAllWindows()