New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

body-matrix

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

body-matrix

Package to Calculate Human Body Measurements

  • 0.4.4
  • PyPI
  • Socket score

Maintainers
1

Human Body Measurement via Video and Image

Demo Video

Install the Package

$ pip install body-matrix

Package Usage


#### LOAD VIDEO, Keypoints and Segmentation Model

from body_matrix import load, infer, process, measure, draw, export

video_path = "/content/drive/MyDrive/Body_Matrix/Raw_Vids/vinmart_customers.mp4"
video_rotate = -90
device = "cuda"
font_path = "/content/drive/MyDrive/Body_Matrix/Roboto-Bold.ttf"

keypoints_model, keypoints_transform = load.keypoints_model(device)
segment_model, segment_transform = load.segment_model(device)

video, frame_counts, fps, sample_frame = load.video(
    video_path=video_path, 
    rotate_angle=video_rotate,
    frame_position=1
)

sample_frame


#### Measure and Visualize Every frame
from body_matrix import score
from torchvision.transforms.functional import to_pil_image

measure_frames = []
measures = []

for index, vid_frame in enumerate(video):
    frame = to_pil_image(vid_frame)
    frame = frame.rotate(video_rotate, expand=True)
    height, leg, hip, shoulder, markers = measure.find_real_measures(
        image_frame=frame,
        device=device,
        keypoints_model=keypoints_model,
        keypoints_transform=keypoints_transform,
        segment_model=segment_model,
        segment_transform=segment_transform
    )

    visualized_frame = draw.visualize_measures(
        height, leg, hip, shoulder, markers, 
        frame, font_path
    )

    measure_frames.append(visualized_frame)
    measures.append(height)


mean, median, minim, maxim = score.best_scores(
    measures,
    100, 
    200
)

best_score, frame_index = score.find_nearest(
    measures, 
    median
)

#### Export Instagram Video with Measures
export.generate_instagram_vid(
    vid_name="instameasures_hoangdo.mp4", 
    vid_width = sample_frame.width, 
    vid_height = sample_frame.height, 
    pil_images = measure_frames, 
    stop_index=frame_index, 
    fps=fps, 
    repeat_rate=2, 
    slow_motion_rate=1
)

instameasures_hoangdo

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc