forked from wyu12/DCT-Computer-Vision
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_reader.py
More file actions
37 lines (29 loc) · 829 Bytes
/
image_reader.py
File metadata and controls
37 lines (29 loc) · 829 Bytes
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
import apriltag
import cv2
import numpy as np
import sys
import matplotlib.pyplot as plt
import os
try:
fname = sys.argv[1]
except:
fname = "data/apriltags.png"
detector = apriltag.Detector()
img = cv2.imread(fname, cv2.IMREAD_GRAYSCALE)
#gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
result = detector.detect(img)
print(result)
output_fname = fname.split(".")[0] + "_output.jpg"
# write to logfile
write = True
if write:
with open("log.csv", "a+") as f:
for res in result:
f.write(fname +","+ res.tag_family +","+ str(res.tag_id)+","+output_fname"\n")
# draw a bounding quadrilateral (optional)
for res in result:
pts = np.array(res.corners, dtype=np.int32)
pts = pts.reshape((-1, 1, 2))
cv2.polylines(img, [pts], True, (255, 0, 0), 3)
# display image
cv2.imshow('frame', img)