opencvを使用してビデオを録画する現在のモードは次のようになります
import cv
capture=cv.CaptureFromCAM(self.deviceID)
img_size=cv.GetSize(cv.QueryFrame(capture))
#create a writer object for the video
writer=cv.CreateVideoWriter(
filename='temp.avi',
fourcc=cv.CV_FOURCC('M','J','P','G'),
fps=15,
frame_size=img_size,
is_color=1)
while True:
#grab the frame
img=cv.QueryFrame(capture)
#write frame to video
cv.WriteFrame(writer,img)
#if 'Enter' or 'Esc' key is pressed, end video capture
c = cv.WaitKey(7) % 0x100
if c == 27 or c == 10:
break
問題は、1 秒あたりのフレーム数を事前に手動で設定する必要があることです。画像をリストに保存し、経過時間を追跡していますが、フレームのないファイルをエクスポートするだけです:
import cv
import time
capture=cv.CaptureFromCAM(self.deviceID)
img_size=cv.GetSize(cv.QueryFrame(capture))
imgList=[]
zero=time.time()
while True:
#grab the frame
img=cv.QueryFrame(capture)
imgList.append(img)
cv.ShowImage("Window1",img)
#if 'Enter' or 'Esc' key is pressed, end video capture
c = cv.WaitKey(7) % 0x100
if c == 27 or c == 10:
break
duration=time.time()-zero
framesPerSecond=len(imgList)/duration)
writer=cv.CreateVideoWriter(
filename='temp.avi',
fourcc=cv.CV_FOURCC('M','J','P','G'),
fps=framesPerSecond,
frame_size=img_size,
is_color=1)
for i in imgList:
cv.writeFrame(writer,i)
少し立ち往生。別の方法に関する提案や既存のコードの微調整は非常に役立ちます。