0

import cv2
import mediapipe as mp
import numpy as np
import sys

mp_drawing = mp.solutions.drawing_utils
mp_pose = mp.solutions.pose
mp_drawing_styles = mp.solutions.drawing_styles



#min_Tracking_confidence = 1 for higher accuracy
pose = mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=1)

#Import Video and Set codec
cap = cv2.VideoCapture(sys.argv[1])
# print("cap :", cap.shape)
fourcc = cv2.VideoWriter_fourcc(*'MP4V')

if cap.isOpened() == False:
    print("Error opening video stream or file")
    raise TypeError

frame_width = int(cap.get(3))
frame_height = int(cap.get(4))


outdir, inputflnm = sys.argv[1][:sys.argv[1].rfind(
    '/')+1], sys.argv[1][sys.argv[1].rfind('/')+1:]
inflnm, inflext = inputflnm.split('.')
out_filename = f'{outdir}{inflnm}_annotated.{inflext}'
# out = cv2.VideoWriter(out_filename, cv2.VideoWriter_fourcc(
#     'M', 'J', 'P', 'G'), 10, (frame_width, frame_height))

out = cv2.VideoWriter(out_filename, fourcc, 30, (frame_width, frame_height))


while cap.isOpened():
    ret, image = cap.read()
    if not ret:
        break
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    image.flags.writeable = False
    results = pose.process(image) #core

    image.flags.writeable = True
    image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)

    # Render detections
    mp_drawing.draw_landmarks(
        image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS)
    out.write(image)

    mp_drawing.plot_landmarks(
        results.pose_world_landmarks, mp_pose.POSE_CONNECTIONS)

    
pose.close()
cap.release()
out.release()


Hello,

I would like to extract skeleton without skeleton+video.

I changed the code to using input video instead of original image in Mediapipe code. and the result was success. the result was the video with skeleton

plus I want to see only skeleton without video. I tired to remove the video but i could not. I appreciate to you if you give me any help!

0 Answers0