146 parser = argparse.ArgumentParser(description=
'AprilTag detection program from a Realsense camera')
147 tag_parser = parser.add_argument_group(
'AprilTag options')
148 tag_parser.add_argument(
'--tag-family', choices=family_mapping.keys(), default=
'36h11', help=
'The family of apriltags to detect')
149 tag_parser.add_argument(
'--tag-size', type=float, default=0.053, help=
'The size of the tags to detect, in meters')
150 tag_parser.add_argument(
'--tag-pose-method', choices=method_mapping.keys(), default=
'homography_vvs', help=
'The method used to estimated the 6D pose of the tags')
151 tag_parser.add_argument(
'--tag-decimate', type=float, required=
False, default=1.0)
152 tag_parser.add_argument(
'--tag-decision-margin', type=float, required=
False, default=2.0)
153 tag_parser.add_argument(
'--tag-hamming-distance', type=int, required=
False, default=50)
155 source_parser = parser.add_argument_group(
'Image acquisition parsing')
156 source_help =
'''Image source. if rs2, we open the realsense stream (if available).
157 Otherwise we consider that it is a stored sequence. It should be specified as /path/to/img-%%d.jpg.
158 See the visp.io.VideoReader documentation for more information'''
159 source_parser.add_argument(
'--source', help=source_help, default=
'rs2')
160 source_parser.add_argument(
'--width', help=
'Image width', default=640)
161 source_parser.add_argument(
'--height', help=
'Image height', default=480)
162 source_parser.add_argument(
'--fps', help=
'Framerate', default=30)
164 camera_parser = parser.add_argument_group(
'Camera intrinsics')
165 camera_parser.add_argument(
'--px', default=0.0, type=float)
166 camera_parser.add_argument(
'--py', default=0.0, type=float)
167 camera_parser.add_argument(
'--u0', default=0.0, type=float)
168 camera_parser.add_argument(
'--v0', default=0.0, type=float)
169 camera_parser.add_argument(
'--kud', default=0.0, type=float)
170 camera_parser.add_argument(
'--kdu', default=0.0, type=float)
173 parser.add_argument(
'--log-path', default=
None, required=
False, help=
'The path to the JSON file where to log the detections.')
175 args, unknown_args = parser.parse_known_args()
178 if len(unknown_args) > 0:
179 print(f
'There were unknown arguments: {unknown_args}', file=sys.stderr)
183 tag_size = args.tag_size
186 frames = frame_source.frames()
189 if args.log_path
is not None:
190 log_path = Path(args.log_path)
195 cam = frame_source.intrinsics()
200 I_disp.resize(frame.getHeight(), frame.getWidth())
201 gray_display = get_display()
202 gray_display.init(I_disp, 0, 0,
'Image')
206 np.copyto(dst=I_disp.numpy(), src=frame.numpy())
208 has_tag, tag_poses = detector.detect(frame, tag_size, cam)
209 if logger
is not None:
210 logger.log_frame(detector, tag_size, cam)
212 Display.display(I_disp)
213 Display.displayText(I_disp, 20, 20,
'Click to stop detection', Color.red)
214 detector.displayFrames(I_disp, tag_poses, cam, 0.05, Color.none)
215 detector.displayTags(I_disp, detector.getTagsCorners())
216 Display.flush(I_disp)
218 clicked = Display.getClick(I_disp, blocking=
False)
222 if logger
is not None:
223 logger.finalize_logging()