Example 3: Set a custom config directory#

ℹ️ Source code and input file(s) -> {pyppbox repo}/examples

The examples/cfg/ directory contains configurations for every supported detector, tracker, and reider, including RF_DETR, ArcFace, and AdaFace. Replace C:/pyppbox_v3 in the module config files with your installed pyppbox directory. Select the stages in cfg/main.yaml; for example:

detector: RF_DETR
tracker: SORT
reider: ArcFace

Use reider: AdaFace to select AdaFace instead. The new modules use cpu in these sample configs. Install requirements/rfdetr.txt and/or requirements/faces.txt using python -m pip install -r from the repository root and obtain the data wheels for the selected modules before running. ArcFace and AdaFace each need their own model and classifier paths. See Supported Detectors, Supported ReIDers, and Devices for requirements and device choices.

Example source#

#################################################################################
# Example of using a custom config directory
#################################################################################

import cv2

from pyppbox.standalone import setConfigDir, detectPeople, trackPeople, reidPeople
from pyppbox.utils.visualizetools import visualizePeople


# Use a custom config directory "cfg"
setConfigDir(config_dir="cfg", load_all=True)

input_video = "data/gta.mp4"
cap = cv2.VideoCapture(input_video)

while cap.isOpened():
    hasFrame, frame = cap.read()

    if hasFrame:

        # Detect people without visualizing
        detected_people, _ = detectPeople(frame, img_is_mat=True, visual=False)

        # Track the detected people
        tracked_people = trackPeople(frame, detected_people, img_is_mat=True)

        # Re-identify the tracked people
        reidentified_people, reid_count = reidPeople(
            frame, 
            tracked_people, 
            img_is_mat=True
        )

        # Visualize people in video frame with reid status `show_reid=reid_count`
        visualized_mat = visualizePeople(
            frame, 
            reidentified_people, 
            show_reid=reid_count
        )
        cv2.imshow("pyppbox: example_03_custom_cfg_directory.py", visualized_mat)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break
cap.release()