我有一堆視頻和depthmaps顯示來自Microsoft Kinect的人體姿勢。使用基於狀態的標籤註釋視頻幀
我可以在視頻中獲得人的骨骼,但我想要做的是從這些骨架數據中識別出某個姿勢。
要做到這一點,我需要用視頻中的每個幀註釋0或1,對應於「壞姿態」和「好姿態」,即幀有一個二進制狀態變量。
我希望能夠在matlab中播放avi文件,然後按下空間在這兩個狀態之間切換,同時將狀態變量添加到給出視頻中每個幀的狀態的數組。
在matlab中是否有一個工具可以做到這一點?否則,matlab不是限制,python,C++或任何其他語言都可以。
我一直在搜索,我發現的大多數東西是用多邊形註釋單個幀。我想要這樣做,也許是視頻的正常幀率的一半。
編輯:我使用miindlek提供的解決方案,並決定分享一些事情,如果有人遇到這一點。我需要在視頻中看到我分配給每個幀的註釋,因此我在視頻的左上角做了一個小圓圈,正如我所顯示的那樣。希望這對以後的其他人有用。我還用waitKey捕獲按下的鍵,然後根據輸出做一些事情。這允許在註釋過程中按下多個鍵。
import numpy as np
import cv2
import os
os.chdir('PathToVideo')
# Blue cicle means that the annotation haven't started
# Green circle is a good pose
# Red is a bad pose
# White circle means we are done, press d for that
# Instructions on how to use!
# Press space to swap between states, you have to press space when the person
# starts doing poses.
# Press d when the person finishes.
# press q to quit early, then the annotations are not saved, you should only
# use this if you made a mistake and need to start over.
cap = cv2.VideoCapture('Video.avi')
# You can INCREASE the value of speed to make the video SLOWER
speed = 33
# Start with the beginning state as 10 to indicate that the procedure has not started
current_state = 10
saveAnnotations = True
annotation_list = []
# We can check wether the video capture has been opened
cap.isOpened()
colCirc = (255,0,0)
# Iterate while the capture is open, i.e. while we still get new frames.
while(cap.isOpened()):
# Read one frame.
ret, frame = cap.read()
# Break the loop if we don't get a new frame.
if not ret:
break
# Add the colored circle on the image to know the state
cv2.circle(frame,(50,50), 50, colCirc, -1)
# Show one frame.
cv2.imshow('frame', frame)
# Wait for a keypress and act on it
k = cv2.waitKey(speed)
if k == ord(' '):
if current_state==0:
current_state = 1
colCirc = (0,0,255)
else:
current_state = 0
colCirc = (0,255,0)
if current_state == 10:
current_state = 0
colCirc = (0,255,0)
if k == ord('d'):
current_state = 11
colCirc = (255,255,255)
# Press q to quit
if k == ord('q'):
print "You quit! Restart the annotations by running this script again!"
saveAnnotations = False
break
annotation_list.append(current_state)
# Release the capture and close window
cap.release()
cv2.destroyAllWindows()
# Only save if you did not quit
if saveAnnotations:
f = open('poseAnnot.txt', 'w')
for item in annotation_list:
print>>f, item
f.close()
你想要實時運行視頻文件嗎? – miindlek
一半的幀速率是好的,它不需要是30幀/秒。 – Gumeo