Skip to main content

A pose detection, tracking, and estimation hub that streamline 2D human sports analysis

Project description

JUXTAPOSE Inference Toolbox 🚀 with ONNX

🍿 Intro

Juxtapose is a 2D multi person pose detection, tracking, and estimation inference toolbox for sports + kinematics analysis.

🍄 Overview

Code mostly adopted from four repos -> ultralytics, mmdeploy, mmdetection, mmpose.

Supported Detectors: rtmdet-s, rtmdet-m, rtmdet-l, groundingdino, yolov8
Supported Pose Estimators: rtmpose-s, rtmpose-m, rtmpose-l
Supported Trackers: bytetrack, botsort

🥒 Updates

👉 Getting Started

Install Using PIP

pip install juxtapose

🧀 Local Development

Mac (CPU only)

git clone https://github.com/ziqinyeow/juxtapose-sdk
cd juxtapose-sdk
pip install -r requirements.txt

Windows (CPU & CUDA)

git clone https://github.com/ziqinyeow/juxtapose-sdk
cd juxtapose-sdk
pip3 install torch --index-url https://download.pytorch.org/whl/cu118
pip install mmcv==2.0.0 -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html
pip install -r requirements.txt

🤩 Feel The Magic

🌄 Basic Usage

from juxtapose import RTM

# Init a rtm model (including rtmdet, rtmpose, tracker)
model = RTM(
    det="rtmdet-m", # see type hinting
    pose="rtmpose-m", # see type hinting
    tracker="bytetrack", # see type hinting
    device="cpu",  # see type hinting
)

# Inference with directory (all the images and videos in the dir will get inference sequentially)
model("data")

# Inference with image
model("data/football.jpeg", verbose=False) # verbose -> disable terminal printing

# Inference with video
model("data/bike.mp4")

# Inference with the YouTube Source
model("https://www.youtube.com/watch?v=1vYvTbDJuFs&ab_channel=PeterGrant", save=True)

🎨 Select Region of Interests (ROIs)

It will first prompt the user to draw the ROIs, press r to remove the existing ROI drawn. After drawing, press SPACE or ENTER or q to accept the ROI drawn. The model will filter out the bounding boxes based on the ROIs.

😁 Note: Press SPACE again to redraw the bounding boxes. See custom implementation with cv2 here.

from juxtapose import RTM

model = RTM(det="groundingdino", pose="rtmpose-l", tracker="none")
model("data/bike.mp4", roi="rect") # rectangle roi

# 1. Draw ROI first
# 2. Press r or R to reset ROI
# 3. Press SPACE or Enter or q or Q to continue with the ROI

🚴‍♂️ Accessing result for each frame: More Flexibility

# Adding custom plot
import cv2
from juxtapose import RTM, Annotator

model = RTM()
annotator = Annotator(thickness=3, font_color=(128, 128, 128)) # see rtm.utils.plotting

# set show to true -> cv2.imshow the frame (you can use cv2 to plot anything in the frame)
# set plot to false -> if you want to ignore default plot -> see rtm.rtm (line `if plot:`)
for result in model("data/bike.mp4", show=True, plot=False, stream=True):
    # do what ever you want with the data
    im, bboxes, kpts = result.im, result.bboxes, result.kpts

    # e.g custom plot anything using cv2 API
    cv2.putText(
        im, "custom text", (100, 100), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (128, 128, 128)
    )

    # use the annotator class -> see rtm.utils.plotting
    annotator.draw_bboxes(
        im, bboxes, labels=[f"children_{i}" for i in range(len(bboxes))]
    )
    annotator.draw_kpts(im, kpts, thickness=4)
    annotator.draw_skeletons(im, kpts)

⚽️ Custom Forward Pass: Full Flexibility

# Custom model forward pass
import cv2
import torch
from juxtapose import RTMDet, RTMPose, Annotator

frame = cv2.imread("data/football.jpeg")
device = "cuda" if torch.cuda.is_available() else "cpu"

# s, m, l
rtmdet = RTMDet("l", device=device)
rtmpose = RTMPose("l", device=device)
annotator = Annotator()


bboxes, scores, labels = rtmdet(frame)  # [[x1, y1, x2, y2], ...], [], []
kpts = rtmpose(frame, bboxes=bboxes)  # shape: (number of human, 17, 2)

annotator.draw_bboxes(frame, bboxes, labels=[f"person_{i}" for i in range(len(bboxes))])
annotator.draw_kpts(frame, kpts, thickness=4)
annotator.draw_skeletons(frame, kpts)

cv2.imshow("frame", frame)
cv2.waitKey(0)
cv2.destroyAllWindows()

Supported Sources

Adopted from ultralytics repository -> see https://docs.ultralytics.com/modes/predict/

Source Argument Type Notes
image 'image.jpg' str or Path Single image file.
URL 'https://ultralytics.com/images/bus.jpg' str URL to an image.
screenshot 'screen' str Capture a screenshot.
PIL Image.open('im.jpg') PIL.Image HWC format with RGB channels.
OpenCV cv2.imread('im.jpg') np.ndarray of uint8 (0-255) HWC format with BGR channels.
numpy np.zeros((640,1280,3)) np.ndarray of uint8 (0-255) HWC format with BGR channels.
torch torch.zeros(16,3,320,640) torch.Tensor of float32 (0.0-1.0) BCHW format with RGB channels.
CSV 'sources.csv' str or Path CSV file containing paths to images, videos, or directories.
video 'video.mp4' str or Path Video file in formats like MP4, AVI, etc.
directory 'path/' str or Path Path to a directory containing images or videos.
glob 'path/*.jpg' str Glob pattern to match multiple files. Use the * character as a wildcard.
YouTube 'https://youtu.be/Zgi9g1ksQHc' str URL to a YouTube video.
stream 'rtsp://example.com/media.mp4' str URL for streaming protocols such as RTSP, RTMP, or an IP address.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

juxtapose-0.0.4.tar.gz (19.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

juxtapose-0.0.4-py3-none-any.whl (403.7 kB view details)

Uploaded Python 3

File details

Details for the file juxtapose-0.0.4.tar.gz.

File metadata

  • Download URL: juxtapose-0.0.4.tar.gz
  • Upload date:
  • Size: 19.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for juxtapose-0.0.4.tar.gz
Algorithm Hash digest
SHA256 68d67feaf210843d27547feb2a75b9649b7af787d6bb6be92ed5dde453b571fa
MD5 71677834d3ad5223fb0d495ea4481644
BLAKE2b-256 4c08c61b853e97a9f7cf13fddf60fada9a17136a3398b80c9d7dee188d056453

See more details on using hashes here.

File details

Details for the file juxtapose-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: juxtapose-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 403.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for juxtapose-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4f09c3f59f7fb64c9699a9bd14d2e261d6b843b683e5c639e738ea362957779c
MD5 400c632dfc1f4bad3e546772be4e484f
BLAKE2b-256 539747a2f8dc73683d13819c418cb4d5281abf95909b542b8051ff7e2d11e835

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page