Skip to content
Snippets Groups Projects
Commit a87decc7 authored by Zhiying Li's avatar Zhiying Li
Browse files

Add A center dot

parent 64cf3f46
No related merge requests found
...@@ -38,30 +38,33 @@ if __name__ == "__main__": ...@@ -38,30 +38,33 @@ if __name__ == "__main__":
#print(len(gray_image.shape)) #print(len(gray_image.shape))
h,w,_ = frame.shape h,w,_ = frame.shape
# put a dot in center of the frame
cv2.circle(frame, (w//2, h//2), 7, (255, 0, 0), -1)
""" """
If you also want to extract the tag pose, estimate_tag_pose should be set to True If you also want to extract the tag pose, estimate_tag_pose should be set to True
and camera_params ([fx, fy, cx, cy]) and camera_params ([fx, fy, cx, cy])
and tag_size (in meters) should be supplied. and tag_size (in meters) should be supplied.
The detect method returns a list of Detection objects each having The detect method returns a list of Detection objects each having
the following attributes the following attributes
(note that the ones with an asterisks are computed only if estimate_tag_pose=True): (note that the ones with an asterisks are computed only if estimate_tag_pose=True):
""" """
""" """
So fx and fy are the focal lengths expressed in pixels. So fx and fy are the focal lengths expressed in pixels.
Cx and Cy describe the coordinates of the so called principal Cx and Cy describe the coordinates of the so called principal
point that should be in the center of the image. point that should be in the center of the image.
It is e.g. not in the center of the image if you cropped the image, It is e.g. not in the center of the image if you cropped the image,
what you should never do when calibrating. what you should never do when calibrating.
fx, fy, cx, cy are given in Pixels in Computer Vision ( and openCV) fx, fy, cx, cy are given in Pixels in Computer Vision ( and openCV)
but e.g. in Photogrammetry you often use mm but e.g. in Photogrammetry you often use mm
""" """
fx = 800 fx = 800
fy = 600 fy = 600
cx = 0 cx = 400
cy = 0 cy = 300
results = detector.detect(gray_image,estimate_tag_pose=True,camera_params=[fx, fy, cx, cy],tag_size=0.16) results = detector.detect(gray_image,estimate_tag_pose=True, camera_params=[fx, fy, cx, cy], tag_size=0.16)
# loop over the AprilTag detection results # loop over the AprilTag detection results
for r in results: for r in results:
...@@ -84,10 +87,14 @@ if __name__ == "__main__": ...@@ -84,10 +87,14 @@ if __name__ == "__main__":
cv2.circle(frame, (cX, cY), 5, (0, 0, 255), -1) cv2.circle(frame, (cX, cY), 5, (0, 0, 255), -1)
# draw the tag family on the image # draw the tag family on the image
print("cX,cY:{},{}".format(cX,cY)) print("cX,cY:{},{}".format(cX,cY))
tagFamily = r.tag_family.decode("utf-8") tagFamily = r.tag_family.decode("utf-8")
tid = r.tag_id tid = r.tag_id
cv2.putText(frame, tagFamily, (ptA[0], ptA[1] - 15), cv2.putText(frame, tagFamily, (ptA[0], ptA[1] - 15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
cv2.putText(frame, "tx: {:.2f} ty: {:.2f} tz:{:.2f}".format(tx[0],ty[0],tz[0]), (ptA[0], ptA[1] + 30), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
print("[INFO] tag id: {}".format(tid)) print("[INFO] tag id: {}".format(tid))
# show the output image after AprilTag detection # show the output image after AprilTag detection
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment