비디오를 프레임으로 변환하려면 아래 코드를 실행하고 있습니다. 문제는 0 KB 크기의 이미지 파일을 만드는 것이고 아무 것도 표시하지 않을 때입니다. 문제가 무엇인지 이해하지 못합니다. 이미지 코덱을 설치해야합니까?openCV imwrite 쓰기 0 KB 이미지 프레임
'''
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 명령은 어디에 있습니까? –
'프레임'을 확인하면 그 프레임이 비어 있음을 알 수 있습니다. 또는'ret'를 검사하여'False '라는 것을 볼 수 있습니다. 즉 프레임이 읽히지 않았습니다. –
ret도 반환하지 않습니다. –