将视频转换为形状(时间,高度,宽度,通道)的张量

时间:2018-07-30 09:41:37

标签: opencv tensorflow image-processing deep-learning data-science

我正在使用给定的代码将视频转换为视频帧

将视频转换为帧:

import cv2
import numpy as np
import os

# Playing video from file:
cap = cv2.VideoCapture('/home/administrator/Desktop/Projects/gait-     recognition/video/p008-n05.avi')
frames = []
try:
        if not os.path.exists('data'):
        os.makedirs('data')
except OSError:
    print ('Error: Creating directory of data')
currentFrame = 0
while(True):
# Capture frame-by-frame
    ret, frame = cap.read()
   # Saves image of the current frame in jpg file
   name = './data/frame' + str(currentFrame) + '.jpg'
print ('Creating...' + name)
cv2.imwrite(name, frame)
frames.append(frame)
# To stop duplicate images
currentFrame += 1
if ret == False:
   break
# When everything done, release the capture
cap.release()
imgs = np.array(frames)

这使我可以将图像输出为单个多维数组的形式。这是必需的

根据形状(时间,高度,宽度,通道)的输入帧创建要素

spatial_features = net_pose.feed_forward_features(imgs)

给出以下错误:用序列设置数组元素

我应该如何修改opencv代码以获得所需的张量图像形状?

0 个答案:

没有答案