File size: 1,852 Bytes
afd2199 577bb6b afd2199 31fdeeb afd2199 cd41c0c a21de06 afd2199 8db8164 c76c2fc 8db8164 fa05982 8db8164 abeb59d a21de06 fcbfb53 afd2199 cadfee9 154e6cd a21de06 8db8164 a21de06 fcbfb53 afd2199 31fdeeb c76c2fc fa05982 cadfee9 31fdeeb 6b7f67c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
import mmpose
import os
from mmpose.apis import MMPoseInferencer
print("[INFO]: Imported modules!")
import gradio as gr
import numpy as np
import cv2
inferencer = MMPoseInferencer('human')
print("[INFO]: Downloaded models!")
def poses(photo):
result_generator = inferencer(photo,
vis_out_dir =".",
return_vis=True,
thickness=2)
video = cv2.VideoCapture(photo)
# Prepare to save video
output_file = os.path.join("output.mp4")
fourcc = cv2.VideoWriter_fourcc(*"mp4v") # Codec for MP4 video
fps = video.get(cv2.CAP_PROP_FPS)
height = 480
width = 640
size = (width,height)
out_writer = cv2.VideoWriter(output_file, fourcc, fps, size)
for result in result_generator:
frame = result["visualization"]
out_writer.write(frame)
print(os.listdir())
print("[INFO]: Visualizing results!")
print(os.listdir())
print()
out_writer.release()
cv2.destroyAllWindows() # Closing window
return output_file
# # specify detection model by alias
# # the available aliases include 'human', 'hand', 'face', 'animal',
# # as well as any additional aliases defined in mmdet
# inferencer = MMPoseInferencer(
# # suppose the pose estimator is trained on custom dataset
# pose2d='custom_human_pose_estimator.py',
# pose2d_weights='custom_human_pose_estimator.pth',
# det_model='human'
# )
def run():
#https://github.com/open-mmlab/mmpose/blob/main/docs/en/user_guides/inference.md
demo = gr.Interface(fn=poses,
inputs=gr.Video(source="webcam"),
outputs=gr.Video())
demo.launch(server_name="0.0.0.0", server_port=7860)
if __name__ == "__main__":
run()
print(os.listdir())
|