私はOpenCV2を使ってウェブカメラでいくつかのタイムアウト写真を撮影しています。私はウェブカメラが見た最新のビューを抽出したいと思います。私はこれを達成しようとします。ウェブカメラから最新のフレームを取得
import cv2
a = cv2.VideoCapture(1)
ret, frame = a.read()
#The following garbage just shows the image and waits for a key press
#Put something in front of the webcam and then press a key
cv2.imshow('a',frame); cv2.waitKey(0); cv2.destroyAllWindows(); [cv2.waitKey(25) for i in range(10)]
#Since something was placed in front of the webcam we naively expect
#to see it when we read in the next image. We would be wrong.
ret, frame = a.read()
cv2.imshow('a',frame); cv2.waitKey(0); cv2.destroyAllWindows(); [cv2.waitKey(25) for i in range(10)]
ウェブカメラの前に置かれた画像は表示されません。
import cv2
a = cv2.VideoCapture(1)
ret, frame = a.read()
#Place something in front of the webcam and then press a key
cv2.imshow('a',frame); cv2.waitKey(0); cv2.destroyAllWindows(); [cv2.waitKey(25) for i in range(10)]
#Purge the buffer
for i in range(10): #Annoyingly arbitrary constant
a.grab()
#Get the next frame. Joy!
ret, frame = a.read()
cv2.imshow('a',frame); cv2.waitKey(0); cv2.destroyAllWindows(); [cv2.waitKey(25) for i in range(10)]
さて、これは動作しますが、それはうるさく非科学的と遅いです:バッファのいくつかの種類がありますかのようにだから私はそうのようなバッファは、ことをパージする...ほとんど
です。バッファー内の最新のイメージのみを特に要求する方法はありますか?それとも、バッファをパージするためのよりよい方法でしょうか?
をすることができます。画像キャプチャの間に遅延があるので、バッファリングの問題が私のために現れます。 – Richard