### Install rtmlib from Source Source: https://github.com/tau-j/rtmlib/blob/main/README.md Install rtmlib from its source code, including dependencies and editable install. ```shell git clone https://github.com/Tau-J/rtmlib.git cd rtmlib pip install -r requirements.txt pip install -e . # [optional] # pip install onnxruntime-gpu # pip install openvino ``` -------------------------------- ### Install rtmlib from PyPI Source: https://github.com/tau-j/rtmlib/blob/main/README.md Install the rtmlib package using pip from the Python Package Index. ```shell pip install rtmlib -i https://pypi.org/simple ``` -------------------------------- ### Run rtmlib WebUI Source: https://github.com/tau-j/rtmlib/blob/main/README.md Launch the WebUI for rtmlib by running the webui.py script. Ensure Gradio is installed. ```shell # Please make sure you have installed gradio # pip install gradio python webui.py ``` -------------------------------- ### 3D Whole Body Pose Estimation with Wholebody3d Source: https://context7.com/tau-j/rtmlib/llms.txt Estimate 3D coordinates for 133 body keypoints using the RTMW3D model via PoseTracker. This example demonstrates video processing and returns 3D coordinates, scores, and 2D projections. ```python import cv2 from rtmlib import PoseTracker, Wholebody3d, draw_skeleton # Use PoseTracker for video processing wholebody3d = PoseTracker( Wholebody3d, det_frequency=7, tracking=False, mode='balanced', backend='onnxruntime', device='cuda' ) cap = cv2.VideoCapture(0) while cap.isOpened(): success, frame = cap.read() if not success: break # Returns 4 outputs for 3D pose keypoints_3d, scores, keypoints_simcc, keypoints_2d = wholebody3d(frame) # keypoints_3d: 3D coordinates # keypoints_2d: 2D projections for visualization img_show = draw_skeleton(frame, keypoints_2d, scores, kpt_thr=0.5) cv2.imshow('3D Pose', img_show) if cv2.waitKey(10) & 0xFF == ord('q'): break cap.release() ``` -------------------------------- ### Initialize Body with Detector and Pose Estimator Source: https://github.com/tau-j/rtmlib/blob/main/README.md Configure the Body solution by providing specific URLs for the detector and pose estimator models, along with their input sizes. Ensure the backend and device are correctly set. ```Python from rtmlib import Body body = Body(det='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_x_8xb8-300e_humanart-a39d44ed.zip', det_input_size=(640, 640), pose='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmpose-x_simcc-body7_pt-body7_700e-384x288-71d7b7e9_20230629.zip', pose_input_size=(288, 384), backend=backend, device=device) ``` -------------------------------- ### Initialize Wholebody with Mode Source: https://github.com/tau-j/rtmlib/blob/main/README.md Instantiate the Wholebody solution by specifying a performance mode. Available modes are 'performance', 'lightweight', and 'balanced'. ```Python from rtmlib import Wholebody wholebody = Wholebody(mode='performance', # 'performance', 'lightweight', 'balanced'. Default: 'balanced' backend=backend, device=device) ``` -------------------------------- ### Initialize Custom Solution for Multi-Class Pose Estimation Source: https://github.com/tau-j/rtmlib/blob/main/README.md Set up a Custom solution for human and animal pose estimation using YOLOX in multiclass mode and ViTPose. For visualization, ensure `openpose_skeleton` is set to `True` in `draw_skeleton`. ```Python # Human and animal pose estimation using YOLOX in multiclass mode and ViTPose # Requires openpose_skeleton = True in draw_skeleton for visualization custom = Custom(det_class='YOLOX', det_mode='multiclass', # or det_categories=[0,23] (for example) det='https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_s.onnx', det_input_size=(640, 640), pose_class='ViTPose', pose='https://huggingface.co/JunkyByte/easy_ViTPose/resolve/main/onnx/apt36k/vitpose-b-apt36k.onnx', pose_input_size=(192, 256), backend=backend, device=device) ``` -------------------------------- ### Initialize Custom Solution with Specific Models Source: https://github.com/tau-j/rtmlib/blob/main/README.md Create a Custom solution by specifying the detector and pose estimator classes and their respective model files. This allows for fine-grained control over the underlying models used for detection and pose estimation. ```Python from rtmlib import Custom # Human pose estimation using YOLOX and RTMPose custom = Custom(det_class='YOLOX', det='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_m_8xb8-300e_humanart-c2c7a14a.ip', det_input_size=(640, 640), pose_class='RTMPose', pose='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmpose-m_simcc-body7_pt-body7_420e-256x192-e48f03d0_20230504.zip', pose_input_size=(192, 256), backend=backend, device=device) ``` -------------------------------- ### Initialize ViTPose Estimator Source: https://github.com/tau-j/rtmlib/blob/main/README.md Instantiate a ViTPose pose estimator using the provided ONNX model file. Configure the backend and device according to your system's capabilities. ```Python # ViTPose pose estimator pose_model = ViTPose(onnx_model='https://huggingface.co/JunkyByte/easy_ViTPose/resolve/main/onnx/apt36k/vitpose-b-apt36k.onnx', backend=backend, device=device) ``` -------------------------------- ### Initialize Custom PoseTracker Source: https://context7.com/tau-j/rtmlib/llms.txt Configure and initialize a custom PoseTracker with specific detection and pose estimation models. Ensure the ONNX models and backend are correctly specified. ```python from functools import partial from rtmlib import PoseTracker, custom_rtmpose, draw_skeleton import cv2 custom_partial = partial( Custom, # Assuming 'Custom' is a defined class or function det_class='YOLOX', det='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_m_8xb8-300e_humanart-c2c7a14a.zip', det_input_size=(640, 640), pose_class='RTMPose', pose='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmpose-m_simcc-body7_pt-body7_420e-256x192-e48f03d0_20230504.zip', pose_input_size=(192, 256), backend='onnxruntime', device='cpu' ) tracker = PoseTracker(custom_partial, det_frequency=10) img = cv2.imread('./demo.jpg') keypoints, scores = custom_rtmpose(img) img_show = draw_skeleton(img, keypoints, scores, kpt_thr=0.43) cv2.imwrite('custom_output.jpg', img_show) ``` -------------------------------- ### Initialize ViTPose for Pose Estimation Source: https://context7.com/tau-j/rtmlib/llms.txt Configure ViTPose for high-accuracy pose estimation, particularly for animal poses. This requires initializing a detector and the ViTPose model. Inference can be performed using detected bounding boxes. ```python import cv2 from rtmlib import YOLOX, ViTPose detector = YOLOX( onnx_model='https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_m.onnx', model_input_size=(640, 640), mode='multiclass', backend='onnxruntime', device='cpu' ) vitpose = ViTPose( onnx_model='https://huggingface.co/JunkyByte/easy_ViTPose/resolve/main/onnx/apt36k/vitpose-b-apt36k.onnx', model_input_size=(192, 256), to_openpose=False, backend='onnxruntime', device='cpu' ) img = cv2.imread('./animal_demo.jpg') bboxes, class_ids = detector(img) keypoints, scores = vitpose(img, bboxes=bboxes) # keypoints: np.ndarray shape (num_animals, 17, 2) # scores: np.ndarray shape (num_animals, 17) ``` -------------------------------- ### Body with Feet Pose Estimation with rtmlib Source: https://context7.com/tau-j/rtmlib/llms.txt Use BodyWithFeet for 26-keypoint pose estimation including feet, following the Halpe26 format. Initialize with mode, skeleton style, backend, and device. ```python import cv2 from rtmlib import BodyWithFeet, draw_skeleton body_with_feet = BodyWithFeet( mode='balanced', # 'performance', 'balanced', 'lightweight' to_openpose=False, backend='onnxruntime', device='cpu' ) img = cv2.imread('./demo.jpg') keypoints, scores = body_with_feet(img) # keypoints: np.ndarray shape (num_persons, 26, 2) # scores: np.ndarray shape (num_persons, 26) img_show = draw_skeleton(img, keypoints, scores, kpt_thr=0.43) cv2.imshow('Body with Feet', img_show) cv2.waitKey(0) ``` -------------------------------- ### Initialize YOLOX Detector with ONNX Model Source: https://github.com/tau-j/rtmlib/blob/main/README.md Load a YOLOX object detector using a specified ONNX model file, which can be a local path or a download URL. Configure the backend and device for inference. ```Python # YOLOX human detector det_model = YOLOX(onnx_model='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_s_8xb8-300e_humanart-3ef259a7.zip', backend=backend, device=device) ``` -------------------------------- ### Initialize RTMPose Estimator Source: https://github.com/tau-j/rtmlib/blob/main/README.md Load an RTMPose pose estimator by providing the ONNX model file path or URL. Ensure the backend and device are correctly configured for optimal performance. ```Python # RTMPose pose estimator pose_model = RTMPose(onnx_model='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmpose-m_simcc-body7_pt-body7_420e-256x192-e48f03d0_20230504.zip', backend=backend, device=device) ``` -------------------------------- ### Initialize YOLOX for Multiclass Detection Source: https://context7.com/tau-j/rtmlib/llms.txt Configure YOLOX for multiclass object detection using COCO classes. This requires a different ONNX model and sets the mode to 'multiclass'. The output includes bounding boxes and class IDs. ```python import cv2 import numpy as np from rtmlib import YOLOX # Multiclass detection (80 COCO classes) detector_multiclass = YOLOX( onnx_model='https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_m.onnx', model_input_size=(640, 640), mode='multiclass', backend='onnxruntime', device='cpu' ) bboxes, class_ids = detector_multiclass(img) # bboxes: np.ndarray shape (num_detections, 4) # class_ids: np.ndarray shape (num_detections,) - COCO class indices ``` -------------------------------- ### Initialize YOLOX for Human Detection Source: https://context7.com/tau-j/rtmlib/llms.txt Set up the YOLOX detector for human-only detection. Specify the ONNX model path, input size, and confidence thresholds. This configuration is suitable for isolating human figures. ```python import cv2 import numpy as np from rtmlib import YOLOX # Human-only detection detector = YOLOX( onnx_model='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_m_8xb8-300e_humanart-c2c7a14a.zip', model_input_size=(640, 640), mode='human', nms_thr=0.45, score_thr=0.7, backend='onnxruntime', device='cpu' ) img = cv2.imread('./demo.jpg') bboxes = detector(img) # bboxes: np.ndarray shape (num_detections, 4) - [x1, y1, x2, y2] ``` -------------------------------- ### Animal Pose Estimation with rtmlib Source: https://context7.com/tau-j/rtmlib/llms.txt Use Animal for 17-keypoint pose estimation on various animals. Requires YOLOX multiclass detection and ViTPose. Initialization parameters include mode, skeleton style, backend, and device. ```python import cv2 from rtmlib import Animal, draw_skeleton ``` -------------------------------- ### Custom Model Configuration with Custom Class Source: https://context7.com/tau-j/rtmlib/llms.txt Configure RTMLib with custom detector and pose estimator classes, including specifying model URLs, input sizes, and backends. Supports various models like YOLOX, RTMPose, RTMO, and ViTPose. ```python import cv2 from functools import partial from rtmlib import Custom, PoseTracker, draw_skeleton # RTMPose with custom models custom_rtmpose = Custom( det_class='YOLOX', det='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_m_8xb8-300e_humanart-c2c7a14a.zip', det_input_size=(640, 640), pose_class='RTMPose', pose='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmpose-m_simcc-body7_pt-body7-halpe26_700e-256x192-4d3e73dd_20230605.zip', pose_input_size=(192, 256), to_openpose=False, backend='onnxruntime', device='cpu' ) # One-stage RTMO (no detector needed) custom_rtmo = Custom( pose_class='RTMO', pose='https://download.openmmlab.com/mmpose/v1/projects/rtmo/onnx_sdk/rtmo-m_16xb16-600e_body7-640x640-39e78cc4_20231211.zip', pose_input_size=(640, 640), to_openpose=False, backend='onnxruntime', device='cuda' ) # ViTPose for animals with multiclass detection custom_animal = Custom( det_class='YOLOX', det_mode='multiclass', det='https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_s.onnx', det_input_size=(640, 640), pose_class='ViTPose', pose='https://huggingface.co/JunkyByte/easy_ViTPose/resolve/main/onnx/apt36k/vitpose-b-apt36k.onnx', pose_input_size=(192, 256), backend='onnxruntime', device='cpu' ) ``` -------------------------------- ### Detect Supported Animals with RTMLib Source: https://context7.com/tau-j/rtmlib/llms.txt Instantiate the Animal class to detect all supported animals or filter by specific COCO class IDs. Requires an image file for processing. ```python animal = Animal( mode='balanced', backend='onnxruntime', device='cpu' ) animal_filtered = Animal( det_categories=[15, 16], # only cats and dogs mode='balanced', backend='onnxruntime', device='cpu' ) img = cv2.imread('./animal_demo.jpg') keypoints, scores = animal(img) # keypoints: np.ndarray shape (num_animals, 17, 2) # scores: np.ndarray shape (num_animals, 17) # Note: Animal pose requires openpose_skeleton=True for visualization img_show = draw_skeleton(img, keypoints, scores, openpose_skeleton=True, kpt_thr=0.43) cv2.imshow('Animal Pose', img_show) cv2.waitKey(0) ``` -------------------------------- ### Draw Bounding Boxes on Image with rtmlib Source: https://context7.com/tau-j/rtmlib/llms.txt Draws detection bounding boxes on an image using a specified color. Requires a detector model to be initialized. ```python import cv2 from rtmlib import YOLOX, draw_bbox detector = YOLOX( onnx_model='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_m_8xb8-300e_humanart-c2c7a14a.zip', model_input_size=(640, 640), backend='onnxruntime', device='cpu' ) img = cv2.imread('./demo.jpg') bboxes = detector(img) img_with_boxes = draw_bbox( img.copy(), bboxes, color=(0, 255, 0) # BGR color for boxes ) cv2.imwrite('detections.jpg', img_with_boxes) ``` -------------------------------- ### Pose Estimation on Webcam Stream or Video Source: https://github.com/tau-j/rtmlib/blob/main/README.md Conduct pose estimation on a live webcam feed or a video file using PoseTracker. Configure detection frequency and model parameters. ```python from rtmlib import Body, Custom, PoseTracker, draw_skeleton import cv2 cap = cv2.VideoCapture(0) # for video file instead of webcam, use cap = cv2.VideoCapture('./demo.mp4') device = 'cpu' backend = 'onnxruntime' openpose_skeleton = False pose_tracker = PoseTracker(Body, mode='balanced', det_frequency=10, # detect every 10 frames backend=backend, device=device, to_openpose=False) # # Or with a custom class # from functools import partial # custom = partial(Custom, # det_class='YOLOX', # det='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_m_8xb8-300e_humanart-c2c7a14a.zip', # det_input_size=(640, 640), # pose_class='RTMPose', # pose='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmpose-m_simcc-body7_pt-body7-halpe26_700e-256x192-4d3e73dd_20230605.zip', # pose_input_size=(192, 256)) # pose_tracker = PoseTracker(custom, # det_frequency=10, # backend=backend, device=device, # to_openpose=False) frame_idx = 0 while cap.isOpened(): success, frame = cap.read() frame_idx += 1 if not success: break keypoints, scores = pose_tracker(frame) img_show = frame.copy() img_show = draw_skeleton(img_show, keypoints, scores, openpose_skeleton=openpose_skeleton, kpt_thr=0.43) cv2.imshow('img', img_show) cv2.waitKey(10) ``` -------------------------------- ### Visualization Utilities Source: https://github.com/tau-j/rtmlib/blob/main/README.md Utilities for visualizing detection and pose estimation results, such as drawing bounding boxes and skeletons. ```APIDOC ## Visualization Utilities ### Description Functions to visualize the results of object detection and pose estimation. ### Available Functions - **draw_bbox**: Draws bounding boxes on an image. - **draw_skeleton**: Draws skeletons on an image, representing pose keypoints. ### Usage Examples #### Drawing Bounding Boxes ```python from rtmlib.draw import draw_bbox # Assuming 'image' is your input image and 'bboxes' is a list of bounding boxes draw_bbox(image, bboxes) ``` #### Drawing Skeletons ```python from rtmlib.draw import draw_skeleton # Assuming 'image' is your input image and 'keypoints' is a list of keypoints # For multiclass detection, set openpose_skeleton=True if needed draw_skeleton(image, keypoints, openpose_skeleton=False) ``` ### Parameters for Visualization Functions #### draw_bbox - **image** (numpy.ndarray) - The input image. - **bboxes** (list) - A list of bounding boxes to draw. Each bounding box can be in various formats, e.g., [x1, y1, x2, y2] or [x_center, y_center, width, height]. - **colors** (list, optional) - A list of colors for the bounding boxes. - **thickness** (int, optional) - The thickness of the bounding box lines. #### draw_skeleton - **image** (numpy.ndarray) - The input image. - **keypoints** (list) - A list of keypoints. Each keypoint set typically includes coordinates and confidence scores for each joint. - **skeleton_type** (str, optional) - Specifies the type of skeleton to draw (e.g., 'human', 'animal'). - **openpose_skeleton** (bool, optional) - If True, uses a skeleton format compatible with OpenPose, useful for multiclass pose estimation. - **colors** (list, optional) - A list of colors for the skeleton joints. - **radius** (int, optional) - The radius of the keypoint circles. - **thickness** (int, optional) - The thickness of the skeleton lines. ``` -------------------------------- ### Hand Pose Estimation with rtmlib Source: https://context7.com/tau-j/rtmlib/llms.txt Use Hand for 21-keypoint hand pose estimation per hand. Currently, only the 'lightweight' mode is supported. Initialize with mode, skeleton style, backend, and device. ```python import cv2 from rtmlib import Hand, draw_skeleton hand = Hand( mode='lightweight', # currently only 'lightweight' is supported to_openpose=False, backend='onnxruntime', device='cpu' ) img = cv2.imread('./hand_demo.jpg') keypoints, scores = hand(img) # keypoints: np.ndarray shape (num_hands, 21, 2) # scores: np.ndarray shape (num_hands, 21) img_show = draw_skeleton(img, keypoints, scores, kpt_thr=0.5) cv2.imshow('Hand Pose', img_show) cv2.waitKey(0) ``` -------------------------------- ### Initialize YOLOX Multi-Class Detector Source: https://github.com/tau-j/rtmlib/blob/main/README.md Instantiate a YOLOX detector for multi-class detection. You can specify `det_mode='multiclass'` or provide a list of COCO class IDs using `det_categories`. ```Python # YOLOX multiclass detector det_model = YOLOX('https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_s.onnx', det_mode='multiclass', # or det_categories=[0,1,etc] if you want specific COCO_CLASSES IDs backend=backend, device=device) ``` -------------------------------- ### Initialize RTMDet for Hand Detection Source: https://context7.com/tau-j/rtmlib/llms.txt Set up RTMDet specifically for hand detection. Use the provided ONNX model URL and configure the input size. The output will be bounding boxes for detected hands. ```python import cv2 from rtmlib import RTMDet hand_detector = RTMDet( onnx_model='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmdet_nano_8xb32-300e_hand-267f9c8f.zip', model_input_size=(320, 320), backend='onnxruntime', device='cpu' ) img = cv2.imread('./hand_demo.jpg') bboxes = hand_detector(img) # bboxes: np.ndarray shape (num_hands, 4) - [x1, y1, x2, y2] ``` -------------------------------- ### Initialize RTMPose for 2D Pose Estimation Source: https://context7.com/tau-j/rtmlib/llms.txt Configure RTMPose for top-down 2D pose estimation. This involves initializing both a detector (like YOLOX) and the RTMPose model. You can perform inference with or without providing bounding boxes. ```python import cv2 import numpy as np from rtmlib import YOLOX, RTMPose # Initialize models detector = YOLOX( onnx_model='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_m_8xb8-300e_humanart-c2c7a14a.zip', model_input_size=(640, 640), backend='onnxruntime', device='cpu' ) pose_model = RTMPose( onnx_model='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmpose-m_simcc-body7_pt-body7_420e-256x192-e48f03d0_20230504.zip', model_input_size=(192, 256), to_openpose=False, backend='onnxruntime', device='cpu' ) img = cv2.imread('./demo.jpg') # Two-stage inference bboxes = detector(img) keypoints, scores = pose_model(img, bboxes=bboxes) # keypoints: np.ndarray shape (num_persons, num_keypoints, 2) # scores: np.ndarray shape (num_persons, num_keypoints) # Without bboxes (uses full image as single bbox) keypoints, scores = pose_model(img) ``` -------------------------------- ### Draw Skeleton on Image with rtmlib Source: https://context7.com/tau-j/rtmlib/llms.txt Renders keypoints and skeleton connections on an image. Supports both MMPose-style and OpenPose-style visualizations. Keypoint confidence threshold and visual parameters can be adjusted. ```python import cv2 import numpy as np from rtmlib import Wholebody, Body, draw_skeleton # MMPose-style visualization (default) wholebody = Wholebody(mode='balanced', to_openpose=False) img = cv2.imread('./demo.jpg') keypoints, scores = wholebody(img) img_mmpose = draw_skeleton( img.copy(), keypoints, scores, openpose_skeleton=False, # MMPose style kpt_thr=0.5, # keypoint confidence threshold radius=2, # keypoint circle radius line_width=2 # skeleton line width ) # OpenPose-style visualization wholebody_openpose = Wholebody(mode='balanced', to_openpose=True) keypoints_op, scores_op = wholebody_openpose(img) img_openpose = draw_skeleton( img.copy(), keypoints_op, scores_op, openpose_skeleton=True, # OpenPose style (thicker, with ellipses) kpt_thr=0.5 ) cv2.imwrite('mmpose_style.jpg', img_mmpose) cv2.imwrite('openpose_style.jpg', img_openpose) ``` -------------------------------- ### Initialize RTMO for One-Stage Pose Estimation Source: https://context7.com/tau-j/rtmlib/llms.txt Set up RTMO for simultaneous detection and pose estimation. Specify the ONNX model, input size, and optionally override inference thresholds. This model is efficient for single-stage processing. ```python import cv2 from rtmlib import RTMO rtmo = RTMO( onnx_model='https://download.openmmlab.com/mmpose/v1/projects/rtmo/onnx_sdk/rtmo-m_16xb16-600e_body7-640x640-39e78cc4_20231211.zip', model_input_size=(640, 640), nms_thr=0.45, score_thr=0.7, to_openpose=False, backend='onnxruntime', device='cuda' ) img = cv2.imread('./demo.jpg') keypoints, scores = rtmo(img) # keypoints: np.ndarray shape (num_persons, 17, 2) # scores: np.ndarray shape (num_persons, 17) # Override thresholds at inference time keypoints, scores = rtmo(img, nms_thr=0.5, score_thr=0.6) ``` -------------------------------- ### High-Level Solutions API Source: https://github.com/tau-j/rtmlib/blob/main/README.md These are high-level APIs that abstract away the complexities of choosing and configuring detectors and pose estimators. You can select a predefined mode or specify the detector and pose models individually. ```APIDOC ## High-Level Solutions API ### Description High-level APIs for common computer vision tasks. These APIs allow you to choose between predefined modes (e.g., 'performance', 'lightweight') or specify custom detector and pose models. ### Available Solutions - PoseTracker - Wholebody - Body - Body_with_feet - Hand - Animal (bird, cat, dog, horse, sheep, cow, elephant, bear, zebra, giraffe) - Custom - Wholebody3d ### Usage Examples #### Using a predefined mode (e.g., Wholebody) ```python from rtmlib import Wholebody wholebody = Wholebody(mode='performance', # Options: 'performance', 'lightweight', 'balanced'. Default: 'balanced' backend=backend, # Specify the backend (e.g., 'onnxruntime', 'tensorrt') device=device) # Specify the device (e.g., 'cpu', 'cuda:0') ``` #### Specifying detector and pose models (e.g., Body) ```python from rtmlib import Body body = Body(det='', det_input_size=(640, 640), pose='', pose_input_size=(288, 384), backend=backend, device=device) ``` #### Using custom classes with Custom API (e.g., Human pose estimation) ```python from rtmlib import Custom custom = Custom(det_class='YOLOX', det='', det_input_size=(640, 640), pose_class='RTMPose', pose='', pose_input_size=(192, 256), backend=backend, device=device) ``` #### Using Custom API with multiclass detection (e.g., Human and animal pose estimation) ```python from rtmlib import Custom custom = Custom(det_class='YOLOX', det_mode='multiclass', # or specify det_categories=[0, 23] det='', det_input_size=(640, 640), pose_class='ViTPose', pose='', pose_input_size=(192, 256), backend=backend, device=device) ``` ### Parameters for Solutions - **mode** (str) - Optional - Specifies the operational mode (e.g., 'performance', 'lightweight', 'balanced'). - **det** (str) - Optional - Path or URL to the detector model. - **det_input_size** (tuple) - Optional - Input size for the detector model (width, height). - **pose** (str) - Optional - Path or URL to the pose estimator model. - **pose_input_size** (tuple) - Optional - Input size for the pose estimator model (width, height). - **det_class** (str) - Optional - The class name of the detector to use (e.g., 'YOLOX', 'RTMDet'). - **pose_class** (str) - Optional - The class name of the pose estimator to use (e.g., 'RTMPose', 'ViTPose'). - **det_mode** (str) - Optional - Mode for the detector ('multiclass' or specific categories). - **det_categories** (list) - Optional - List of category IDs for multiclass detection. - **backend** (str) - Required - The inference backend to use (e.g., 'onnxruntime', 'tensorrt'). - **device** (str) - Required - The device to run inference on (e.g., 'cpu', 'cuda:0'). ``` -------------------------------- ### Video Pose Tracking with PoseTracker Source: https://context7.com/tau-j/rtmlib/llms.txt Utilize PoseTracker for efficient video processing with detection frequency control and IoU-based person tracking. Supports various pose estimation models like Wholebody. ```python import cv2 from rtmlib import PoseTracker, Wholebody, Body, draw_skeleton # Basic pose tracker with Wholebody pose_tracker = PoseTracker( Wholebody, det_frequency=10, # run detection every 10 frames (faster) tracking=True, # enable IoU-based tracking tracking_thr=0.3, # IoU threshold for tracking mode='balanced', to_openpose=False, backend='onnxruntime', device='cpu' ) cap = cv2.VideoCapture(0) # webcam # cap = cv2.VideoCapture('./demo.mp4') # video file while cap.isOpened(): success, frame = cap.read() if not success: break keypoints, scores = pose_tracker(frame) img_show = draw_skeleton(frame, keypoints, scores, kpt_thr=0.43) cv2.imshow('Pose Tracking', img_show) if cv2.waitKey(10) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows() # Reset tracker for new video pose_tracker.reset() ``` -------------------------------- ### Wholebody Pose Estimation with rtmlib Source: https://context7.com/tau-j/rtmlib/llms.txt Use Wholebody for 133-keypoint full body pose estimation. Initialize with desired mode, skeleton style, backend, and device. Supports image and video processing. ```python import cv2 from rtmlib import Wholebody, draw_skeleton # Initialize wholebody detector # mode options: 'performance', 'balanced', 'lightweight' wholebody = Wholebody( mode='balanced', to_openpose=False, # True for OpenPose-style skeleton backend='onnxruntime', # 'opencv', 'onnxruntime', 'openvino' device='cpu' # 'cpu', 'cuda', 'mps' ) # Process single image img = cv2.imread('./demo.jpg') keypoints, scores = wholebody(img) # keypoints: np.ndarray shape (num_persons, 133, 2) - x,y coordinates # scores: np.ndarray shape (num_persons, 133) - confidence per keypoint # Visualize results img_show = draw_skeleton(img, keypoints, scores, kpt_thr=0.5) cv2.imshow('Wholebody Pose', img_show) cv2.waitKey(0) # Process video stream cap = cv2.VideoCapture('./demo.mp4') while cap.isOpened(): success, frame = cap.read() if not success: break keypoints, scores = wholebody(frame) frame = draw_skeleton(frame, keypoints, scores, kpt_thr=0.43) cv2.imshow('Video', frame) if cv2.waitKey(10) & 0xFF == ord('q'): break cap.release() ``` -------------------------------- ### Low-Level Models API Source: https://github.com/tau-j/rtmlib/blob/main/README.md These are low-level APIs for specific models, allowing direct instantiation of detectors or pose estimators. You can provide the model path or URL for ONNX models. ```APIDOC ## Low-Level Models API ### Description Low-level APIs for instantiating specific object detection and pose estimation models. You can load models from local paths or URLs. ### Available Models #### Detectors - YOLOX (human and multiclass) - RTMDet #### Pose Estimators - RTMPose (various keypoint configurations, including 3D) - ViTPose (various keypoint configurations, including animal) ### Usage Examples #### YOLOX Human Detector ```python from rtmlib import YOLOX det_model = YOLOX(onnx_model='', backend=backend, device=device) ``` #### YOLOX Multiclass Detector ```python from rtmlib import YOLOX det_model = YOLOX('', det_mode='multiclass', # or det_categories=[0, 1, etc.] backend=backend, device=device) ``` #### RTMPose Pose Estimator ```python from rtmlib import RTMPose pose_model = RTMPose(onnx_model='', backend=backend, device=device) ``` #### ViTPose Pose Estimator ```python from rtmlib import ViTPose pose_model = ViTPose(onnx_model='', backend=backend, device=device) ``` ### Parameters for Models - **onnx_model** (str) - Required - Path or URL to the ONNX model file (.onnx or .zip). - **det_mode** (str) - Optional - Mode for the detector ('multiclass' or specific categories). - **det_categories** (list) - Optional - List of category IDs for multiclass detection. - **backend** (str) - Required - The inference backend to use (e.g., 'onnxruntime', 'tensorrt'). - **device** (str) - Required - The device to run inference on (e.g., 'cpu', 'cuda:0'). ``` -------------------------------- ### Pose Estimation on Single Image Source: https://github.com/tau-j/rtmlib/blob/main/README.md Perform whole-body pose estimation on a single image using rtmlib. Specify the device, backend, and skeleton style. ```python import cv2 from rtmlib import Wholebody, draw_skeleton img = cv2.imread('./demo.jpg') device = 'cpu' # cpu, cuda, mps backend = 'onnxruntime' # opencv, onnxruntime, openvino openpose_skeleton = False # True for openpose-style (required for animals), False for mmpose-style wholebody = Wholebody(to_openpose=openpose_skeleton, mode='balanced', # 'performance', 'lightweight', 'balanced'. Default: 'balanced' backend=backend, device=device) keypoints, scores = wholebody(img) # visualize # if you want to use black background instead of original image, # img = np.zeros(img.shape, dtype=np.uint8) img = draw_skeleton(img, keypoints, scores, kpt_thr=0.5, to_openpose=openpose_skeleton) cv2.imshow('img', img) cv2.waitKey(0) ``` -------------------------------- ### Body Pose Estimation with rtmlib Source: https://context7.com/tau-j/rtmlib/llms.txt Use Body for 17-keypoint COCO-style human pose estimation. Supports two-stage (detector + pose) and one-stage (RTMO) approaches. Custom model URLs can be provided. ```python import cv2 from rtmlib import Body, draw_skeleton # Two-stage approach (YOLOX + RTMPose) body = Body( mode='balanced', to_openpose=False, backend='onnxruntime', device='cpu' ) # One-stage approach (RTMO - faster but slightly less accurate) body_rtmo = Body( pose='rtmo', # triggers one-stage RTMO model mode='balanced', backend='onnxruntime', device='cuda' ) # Inference img = cv2.imread('./demo.jpg') keypoints, scores = body(img) # keypoints: np.ndarray shape (num_persons, 17, 2) # scores: np.ndarray shape (num_persons, 17) # Custom model URLs body_custom = Body( det='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_x_8xb8-300e_humanart-a39d44ed.zip', det_input_size=(640, 640), pose='https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmpose-x_simcc-body7_pt-body7_700e-384x288-71d7b7e9_20230629.zip', pose_input_size=(288, 384), backend='onnxruntime', device='cpu' ) img_show = draw_skeleton(img, keypoints, scores, kpt_thr=0.5) cv2.imwrite('output.jpg', img_show) ``` -------------------------------- ### RTMPose - 2D Pose Estimation Source: https://context7.com/tau-j/rtmlib/llms.txt Top-down pose estimation model that takes bounding boxes and estimates keypoints. ```APIDOC ## RTMPose - 2D Pose Estimation ### Description Top-down pose estimation model that takes bounding boxes and estimates keypoints. ### Method POST ### Endpoint /api/models/rtmpose ### Parameters #### Query Parameters - **onnx_model** (string) - Required - Path to the ONNX model file. - **model_input_size** (tuple) - Required - Input size for the model (width, height). - **to_openpose** (boolean) - Optional - Whether to convert keypoints to OpenPose format. Defaults to False. - **backend** (string) - Optional - Inference backend ('onnxruntime', 'tensorrt', etc.). Defaults to 'onnxruntime'. - **device** (string) - Optional - Inference device ('cpu', 'cuda'). Defaults to 'cpu'. #### Request Body - **image** (numpy.ndarray or file) - Required - Input image. - **bboxes** (numpy.ndarray) - Optional - Bounding boxes for persons. If not provided, the full image is used as a single bounding box. ### Request Example (with bboxes) ```json { "onnx_model": "https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/rtmpose-m_simcc-body7_pt-body7_420e-256x192-e48f03d0_20230504.zip", "model_input_size": [192, 256], "to_openpose": false, "backend": "onnxruntime", "device": "cpu" } ``` ### Response #### Success Response (200) - **keypoints** (numpy.ndarray) - Estimated keypoints for each person. Shape (num_persons, num_keypoints, 2). - **scores** (numpy.ndarray) - Confidence scores for each keypoint. Shape (num_persons, num_keypoints). ``` -------------------------------- ### ViTPose - Vision Transformer Pose Estimation Source: https://context7.com/tau-j/rtmlib/llms.txt ViTPose model for high-accuracy pose estimation, especially useful for animal pose. ```APIDOC ## ViTPose - Vision Transformer Pose Estimation ### Description ViTPose model for high-accuracy pose estimation, especially useful for animal pose. ### Method POST ### Endpoint /api/models/vitpose ### Parameters #### Query Parameters - **onnx_model** (string) - Required - Path to the ONNX model file. - **model_input_size** (tuple) - Required - Input size for the model (width, height). - **to_openpose** (boolean) - Optional - Whether to convert keypoints to OpenPose format. Defaults to False. - **backend** (string) - Optional - Inference backend ('onnxruntime', 'tensorrt', etc.). Defaults to 'onnxruntime'. - **device** (string) - Optional - Inference device ('cpu', 'cuda'). Defaults to 'cpu'. #### Request Body - **image** (numpy.ndarray or file) - Required - Input image. - **bboxes** (numpy.ndarray) - Optional - Bounding boxes for animals. If not provided, the full image is used as a single bounding box. ### Request Example ```json { "onnx_model": "https://huggingface.co/JunkyByte/easy_ViTPose/resolve/main/onnx/apt36k/vitpose-b-apt36k.onnx", "model_input_size": [192, 256], "to_openpose": false, "backend": "onnxruntime", "device": "cpu" } ``` ### Response #### Success Response (200) - **keypoints** (numpy.ndarray) - Estimated keypoints for each animal. Shape (num_animals, 17, 2). - **scores** (numpy.ndarray) - Confidence scores for each keypoint. Shape (num_animals, 17). ``` -------------------------------- ### YOLOX - Object Detection Source: https://context7.com/tau-j/rtmlib/llms.txt YOLOX detector supporting human detection and multiclass COCO object detection. ```APIDOC ## YOLOX - Object Detection ### Description YOLOX detector supporting human detection and multiclass COCO object detection. ### Method POST ### Endpoint /api/models/yolox ### Parameters #### Query Parameters - **onnx_model** (string) - Required - Path to the ONNX model file. - **model_input_size** (tuple) - Required - Input size for the model (width, height). - **mode** (string) - Optional - 'human' for human-only detection, 'multiclass' for COCO classes. Defaults to 'multiclass'. - **nms_thr** (float) - Optional - Non-maximum suppression threshold. - **score_thr** (float) - Optional - Score threshold for detections. - **backend** (string) - Optional - Inference backend ('onnxruntime', 'tensorrt', etc.). Defaults to 'onnxruntime'. - **device** (string) - Optional - Inference device ('cpu', 'cuda'). Defaults to 'cpu'. ### Request Example ```json { "onnx_model": "https://download.openmmlab.com/mmpose/v1/projects/rtmposev1/onnx_sdk/yolox_m_8xb8-300e_humanart-c2c7a14a.zip", "model_input_size": [640, 640], "mode": "human", "nms_thr": 0.45, "score_thr": 0.7, "backend": "onnxruntime", "device": "cpu" } ``` ### Response #### Success Response (200) - **bboxes** (numpy.ndarray) - Detected bounding boxes in the format [x1, y1, x2, y2]. Shape (num_detections, 4). - **class_ids** (numpy.ndarray) - Class IDs for each detection (only for 'multiclass' mode). Shape (num_detections,). ``` -------------------------------- ### Hand Detection Model Source: https://github.com/tau-j/rtmlib/blob/main/README.md This model is specifically trained for hand detection. It uses a nano-sized RTMDet architecture. ```text RTMDet-nano 320x320 76.0 trained on 5 datasets ```