2016-09-24 43 views
0

我正在修補OpenCV,我在計算什麼fps我應該錄製攝像頭鏡頭時遇到了一些麻煩。當我在15 fps上錄製時,錄製的視頻比「現實生活」要快得多。我想知道是否有一個「最佳」的fps,我可以記錄,只要拍攝視頻花費的時間,記錄就會是,正好是什麼是記錄OpenCV視頻的最佳fps?

以下是我正在運行的程序(雖然我認爲這是無關緊要的問題):

import cv2 

cap = cv2.VideoCapture(0) 

# Define the codec and create VideoWriter object 
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v') 
fps = 15.0 # Controls the fps of the video created: todo look up optimal fps for webcam 
out = cv2.VideoWriter() 

success = out.open('../assets/output.mp4v',fourcc, fps, (1280,720),True) 

while(cap.isOpened()): 
    ret, frame = cap.read() 
    if ret==True: 
     frame = cv2.flip(frame,1) 
     # write the flipped frame 
     out.write(frame) 
     cv2.imshow('frame',frame) 

     # If user presses escape key program terminates 
     userInput = cv2.waitKey(1) 
     if userInput == 27: 
      break 
    else: 
     break 

# Release everything if job is finished 
cap.release() 
out.release() 
cv2.destroyAllWindows() 

回答

1

比方說,你的攝像頭,支持25fps的記錄。如果您在相機以25 FPS錄製時捕捉15 FPS,則視頻將比實際壽命快大約1.6倍。

您可以通過get(CAP_PROP_FPS)get(CV_CAP_PROP_FPS)找出幀頻,但除非視頻源是視頻文件,否則無效。

對於你必須計算攝像機或攝像頭(估計)FPS編程:

num_frames = 240; # Number of frames to capture 

print "Capturing {0} frames".format(num_frames) 

start = time.time()# Start time 

# Grab a few frames 
for i in xrange(0, num_frames) : 
    ret, frame = video.read() 

end = time.time() # End time 

seconds = end - start # Time elapsed 
print "Time taken : {0} seconds".format(seconds) 

# Calculate frames per second 
fps = num_frames/seconds; 
print "Estimated frames per second : {0}".format(fps); 

所以通過記錄前240幀作爲樣品視頻源的該程序估計的幀速率,然後計算時間增量。最後,簡單分工的結果爲您提供FPS。

相關問題