Я хочу извлечь детали из видео из видео в следующем формате CSV. Я попробовал это, и я могу только извлечь позиции каждой позы. Как я могу получить ротации? Когда я искал, я обнаружил, что вращения рассчитываются вручную, но это не кажется практичным. Как я могу это сделать?
Введите описание изображения здесь < /p>
frame_number,bone_name,rotation_x,rotation_y,rotation_z,position_x,position_y,position_z
1,NOSE,0.0,0.0,0.0,0.5938315391540527,0.37338733673095703,-1.0306247472763062
1,LEFT_EYE_INNER,0.0,0.0,0.0,0.6135685443878174,0.34751778841018677,-1.012925148010254
1,LEFT_EYE,0.0,0.0,0.0,0.6254734992980957,0.34872227907180786,-1.0124881267547607
< /code>
def extract_pose(video_file, output_csv):
"""
Extracts pose landmarks from a video and saves them to a CSV file in the format:
frame_number, bone_name, rotation_x, rotation_y, rotation_z, position_x, position_y, position_z
Args:
video_file (str): Path to the input video file.
output_csv (str): Path to the output CSV file.
Returns:
None
"""
# MediaPipe setup for pose
mp_pose = mp.solutions.pose
pose = mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5)
cap = cv2.VideoCapture(video_file)
frame_count = 0
with open(output_csv, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['frame_number', 'bone_name', 'rotation_x', 'rotation_y', 'rotation_z', 'position_x', 'position_y', 'position_z'])
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
frame_count += 1
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# Process full-body pose
pose_results = pose.process(rgb_frame)
if pose_results.pose_landmarks:
for i, landmark in enumerate(pose_results.pose_landmarks.landmark):
bone_name = mp_pose.PoseLandmark(i).name
position_x = landmark.x
position_y = landmark.y
position_z = landmark.z
rotation_x = 0.0 # MediaPipe doesn't provide rotation directly, set to 0 for now
rotation_y = 0.0 # Set to 0 for now
rotation_z = 0.0 # Set to 0 for now
# Write the data to CSV file
writer.writerow([frame_count, bone_name, rotation_x, rotation_y, rotation_z, position_x, position_y, position_z])
# Optional: Display the video feed with pose landmarks
# cv2.imshow('Pose Detection', frame)
# Stop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
< /code>
I want to correct this code for get csv file output as mentioned above
Подробнее здесь: https://stackoverflow.com/questions/793 ... s-csv-file