私は以下のコードを実行してビデオをフレームに変換しています。問題は、0 KBのサイズの画像ファイルを作成していて、開いたときに何も表示されていないということです。問題の原因を理解できません。 Imageコーデックをインストールする必要はありますか?openCV imwriteは0kbのイメージフレームを書きます
'''
Using OpenCV takes a mp4 video and produces a number of images. I am using OpenCV 3.3.0 version and Python 2.7
Which will produce a folder called data with the images, There will be 2000+ images for example.mp4.
'''
import cv2
import numpy as np
import os
# Playing video from file:
try:
cap = cv2.VideoCapture('aa.mkv')
except:
print "Could not open video file"
raise
print cap.grab()
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()
if not frame is None:
# Saves image of the current frame in jpg file
name = './data/frame' + str(currentFrame) + '.jpg'
print ('Creating...' + name)
cv2.imwrite(name, frame)
#cv2.imshow(name, frame)
else:
break
# To stop duplicate images
currentFrame += 1
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
imwriteコマンドはどこですか? –
'frame'をチェックすると、それは空白になります。代わりに、あなたの 'ret'をチェックして、それが' False'であること、つまりフレームが読み込まれていないことを確認することができます。 –
retも何も返さない。 –