使用基于状态的标签注释视频帧 [英] Annotating video frames with a label based on state

查看:100
本文介绍了使用基于状态的标签注释视频帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆视频和深度图,显示了Microsoft Kinect的人体姿势.

I have a bunch of videos and depthmaps showing human poses from the Microsoft Kinect.

我可以在视频中获得人体的骨骼,但是我想做的就是从骨骼数据中识别出某个姿势.

I can get a skeleton of the human in the video but what I want to do is recognize a certain pose from this skeleton data.

为此,我需要用0或1注释视频中的每个帧,分别对应不良姿势"和良好姿势",即该帧具有二进制状态变量.

To do that I need to annotate each frame in the videos with a 0 or 1, corresponding to "bad pose" and "good pose", i.e. the frame has a binary state variable.

我希望能够在matlab中播放avi文件,然后按空格键在这两种状态之间切换,并同时将状态变量添加到数组中,以提供视频中每个帧的状态.

I want to be able to playback the avi file in matlab and then press space to switch between these two states and simultaneously add the state variable to an array giving the state for each frame in the video.

matlab中是否有一个工具可以做到这一点?否则,matlab不受限制,python,C ++或任何其他语言都可以.

Is there a tool in matlab that can do this? Otherwise matlab is not a restriction, python, C++ or any other language is fine.

我一直在四处搜寻,发现的大多数东西都是用多边形注释单个框架.我想以视频正常帧率的一半来执行此操作.

I have been googling around, and most of the stuff I have found is to annotate individual frames with a polygon. I want to do this at maybe half the regular framerate of the video.

我使用了miindlek提供的解决方案,并决定分享一些东西,如果有人碰到这个问题.我需要在视频中看到为每个帧分配的注释,因此在显示视频时,我在视频的左上角做了一个小圆圈.希望这对以后的其他人有用.我还捕获了用waitKey按下的键,然后根据输出执行一些操作.这样可以在批注期间按下多个键.

I used the solution provided by miindlek and decided to share a few things if someone runs into this. I needed to see in the video what annotation I was assigning to each frame, so I made a small circle in the upper left corner of the video as I displayed it. Hopefully this will be useful for someone else later. I also capture the key pressed with waitKey and then do something based on the output. This allows for multiple keys to be pressed during the annotations.

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()

推荐答案

解决任务的一种方法是将opencv库与python结合使用,如本

One way to solve your task is using the opencv library with python, as described in this tutorial.

import numpy as np
import cv2

cap = cv2.VideoCapture('video.avi')

current_state = False
annotation_list = []

while(True):
    # Read one frame.
    ret, frame = cap.read()
    if not ret:
        break

    # Show one frame.
    cv2.imshow('frame', frame)

    # Check, if the space bar is pressed to switch the mode.
    if cv2.waitKey(1) & 0xFF == ord(' '):
        current_state = not current_state

    annotation_list.append(current_state)

# Convert the list of boolean values to a list of int values.    
annotation_list = map(int, annotation_list)
print annotation_list

cap.release()
cv2.destroyAllWindows()

变量 annotation_list 包含每一帧的所有注释.要在两种模式之间切换,必须按空格键.

The variable annotation_list contains all annotations for each frame. To switch between the two modes, you have to press the space bar.

这篇关于使用基于状态的标签注释视频帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆