Skip to main content

Package to Calculate Human Body Measurements

Project description

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

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

body_matrix-0.4.4.tar.gz (12.7 kB view hashes)

Uploaded Source

Built Distribution

body_matrix-0.4.4-py3-none-any.whl (14.5 kB view hashes)

Uploaded Python 3

Supported by

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