Reputation: 9
i wanted to work on pose correction system for my college final year project and needed a my own datasets. but i am not able to get the pose coordinates from the video into CSV file no matter what i try. I tried but there is no code or reference which can help me in it. So can anyone please tell how should i do it.
this is my code
import cv2
mp_drawing = mp.solutions.drawing_utils
mp_pose = mp.solutions.pose
cap = cv2.VideoCapture('C:/Users/lenovo/Downloads/pexels-julia-larson-6455077.mp4')
count=0
## Setup mediapipe instance
with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:
while cap.isOpened():
ret, frame = cap.read()
# Recolor image to RGB
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image.flags.writeable = False
# Make detection
results = pose.process(image)
# Recolor back to BGR
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
# Extract landmarks
try:
landmarks = results.pose_landmarks.landmark
LANDMARKS = landmarks[mp_pose.PoseLandmark.value]
df = pd.DataFrame(LANDMARKS,columns)
df.to_csv (r'C:/Users/lenovo/Downloads/dataset4.csv', index = False, header=True)
except:
pass
# Render detections
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
mp_drawing.DrawingSpec(color=(245,117,66), thickness=2, circle_radius=2),
mp_drawing.DrawingSpec(color=(245,66,230), thickness=2, circle_radius=2)
)
cv2.imshow('Mediapipe Feed', image)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Upvotes: 0
Views: 208
Reputation: 2082
Try moving the lines saving the data to pandas
DataFrame
outside the while loop
.
Create an empty list: landmarks_list
For each frame append landmarks to list.
Run the followning lines after the while has finished running over the video frames
df = pd.DataFrame(landmarks_list,columns)
df.to_csv (r'C:/Users/lenovo/Downloads/dataset4.csv', index = False, header=True)
Upvotes: 1