import time
import pupil_apriltags as apriltag
import cv2
def cv_show(name, img):
cv2.imshow(name, img)
cv2.waitKey(1)
def get_DroidCam_url(ip, port=4747, res='1080p'):
res_dict = {
'1080p': '720x1280'
}
url = f'http://{ip}:{port}/mjpegfeed?{res_dict[res]}'
return url
camera = cv2.VideoCapture(get_DroidCam_url('192.168.3.28', 4747, '1080p'))
grabbed, original_map = camera.read()
while 1:
grabbed, original_map = camera.read()
gary_map = cv2.cvtColor(original_map, cv2.COLOR_BGR2GRAY) ## 转换为灰度图
detector = apriltag.Detector()
result = detector.detect(gary_map)
for i in result:
cv2.rectangle(original_map, tuple(i.corners[0].astype(int)), tuple(i.corners[2].astype(int)),color=(0, 0, 255), thickness=3)
# print(result)
print(tuple(i.corners[0].astype(int)), tuple(i.corners[2].astype(int)))
cv_show('original',original_map)