diff --git a/Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread_AT.py b/Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread_AT.py index 1a7e10caef5a2a75ea58ef9e88869e1b2947efd5..43fe176301ae12e5e5506a58a0bcf602bacf79ad 100644 --- a/Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread_AT.py +++ b/Code/Ball_Detection/PyTorch_with_ESPCAM/imageTread_AT.py @@ -38,30 +38,33 @@ if __name__ == "__main__": #print(len(gray_image.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 - and camera_params ([fx, fy, cx, cy]) - and tag_size (in meters) should be supplied. - The detect method returns a list of Detection objects each having - the following attributes + 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 tag_size (in meters) should be supplied. + The detect method returns a list of Detection objects each having + the following attributes (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. - Cx and Cy describe the coordinates of the so called principal - 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, + Cx and Cy describe the coordinates of the so called principal + 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, 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 """ fx = 800 fy = 600 - cx = 0 - cy = 0 - results = detector.detect(gray_image,estimate_tag_pose=True,camera_params=[fx, fy, cx, cy],tag_size=0.16) + cx = 400 + cy = 300 + 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 for r in results: @@ -84,10 +87,14 @@ if __name__ == "__main__": cv2.circle(frame, (cX, cY), 5, (0, 0, 255), -1) # draw the tag family on the image print("cX,cY:{},{}".format(cX,cY)) + + tagFamily = r.tag_family.decode("utf-8") tid = r.tag_id - cv2.putText(frame, tagFamily, (ptA[0], ptA[1] - 15), - cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) + cv2.putText(frame, tagFamily, (ptA[0], ptA[1] - 15), 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)) # show the output image after AprilTag detection