Skip to content

Detect and Annotate ​

SUMMARY

detect_and_annotate() detects the target's corners on an image and returns an annotated copy plus the number of corners found.

SUPPORTED TARGETS

Available on CharucoTarget and ZividTarget. CharucoTarget returns however many ChArUco corners were found, so partial views give a partial count. ZividTarget returns either every inner corner or 0, since its board frame needs the full grid and the fiducial (see ZividTarget).

UNITS

The input image can be BGR, BGRA or grayscale. Returns a BGR annotated copy and the corner count as an integer.

The Skill ​

python
annotated_image, num_corners = target.detect_and_annotate(image)

The Code ​

python
import cv2

from telekinesis.axon.targets import CharucoTarget

charuco = CharucoTarget(squares_x=6, squares_y=9, square_length=0.012, marker_length=0.009)

# Render a board that matches the target so the example runs as is. With a real camera, pass a BGR
# frame of your printed board instead, for example cv2.imread("frame.png").
dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_1000)  # the default aruco_dict_id=3
board = cv2.aruco.CharucoBoard((6, 9), 0.012, 0.009, dictionary)
image = cv2.cvtColor(board.generateImage((600, 900), marginSize=40), cv2.COLOR_GRAY2BGR)

annotated_image, num_corners = charuco.detect_and_annotate(image)

print(f"Detected {num_corners} ChArUco corners")  # 40 for this 6 x 9 board
cv2.imwrite("frame_annotated.png", annotated_image)

cv2.imread returns None instead of raising when the file does not exist, and detect_and_annotate then fails with a TypeError about incompatible arguments. Check that image is not None when loading your own frames.

With a ZividTarget, the annotation also draws the fiducial and the board axes (x red, y green) from the origin:

python
from telekinesis.axon.targets import ZividTarget

zivid = ZividTarget(squares=(7, 8), square_size=0.030, aruco_dict_id="DICT_4X4_50")
annotated_image, num_corners = zivid.detect_and_annotate(image)  # 42 or 0