TDCam

class TDCam

A tag detector camera class which opens a webcam capture and performs Apriltag detection on the image frame. One TDCam object per attached webcam.

Subclassed by CalibrationCamWorker, TDCamWorker

Public Functions

TDCam() = delete

No default constructor.

explicit TDCam(CamParams &c_params, const std::map<int, Pose_single> &tag_layout, bool enable_video_writer = false)

Assign param structs to local member variables.

Parameters:
  • c_params – The camera configuration to use during setup and computations.

  • tag_layout – The Apriltag field layout to use during computations.

virtual ~TDCam()

Ensure all Apriltag dynamic memory is cleaned up in child classes.

void InitCap()

Create the cv::VideoCapture object to pull frames from. Try to start capture at the desired resolution, exposure, and FPS specified in the _c_params struct. Disable autoexposure. Note: OpenCV doesn’t force the cameras to run at the specified properties, the camera will choose whichever parameters are closest to its available features. Camera exposure setting is not supported on some cameras (Logitech C505e for example).

void InitRecordedCap()

Create the cv::VideoCapture from a prerecorded .avi file for evaluation. Opens the file at the specified frame rate and resolution as configured in the .yml file.

virtual void InitDetector()

Create the Apriltag detector with the specified detector parameters.

virtual void CloseCap()

Gracefully close the capture device.

cv::Mat GetImage()

Get an image frame from the opened capture device. Will block until the capture returns an image.

Returns:

An image frame from the capture device.

void SaveImage(const cv::Mat &img)

Save the image to a video file. Blocks until image is written.

void Undistort(cv::Mat &img)

Undistort an image using the provided camera intrinsic parameters and distortion coefficients. Retains original image resolution.

Parameters:

img – [input:output] The image to undistort.

TagArray GetTagsFromImage(const cv::Mat &img)

Run the Apriltag detector on an input image and find all possible tag poses for all tags in the image. Calculates the pose for each tag in four frames: tag, tag w.r.t. camera, tag w.r.t. robot, and robot w.r.t. world. Organizes these detections by tag ID into the TagArray object.

Parameters:

img – The image to run the Apriltag detector on.

Returns:

All possible tag detections found in the image.

cv::Mat DrawTagBoxesOnImage(const TagArray &tags, const cv::Mat &img)

Given an image and its corresponding tag detections, draw a bounding box around the detected tags in the frame and label the tag with its ID.

Parameters:
  • tags – All tags detected in this image.

  • img – The image to draw on.

Returns:

The annotated image with bounding boxes and labels.

void ImShow(const std::string &title, int timeout, const cv::Mat &img)

Use OpenCVs imshow function to display an image.

Parameters:
  • title – Title of the image window.

  • timeout – How long to wait before closing the image window, in milliseconds.

  • img – The image to display in the window.