2020年12月19日星期六

Read last frame from PiCamera Ring Buffer

I am building a motion detector using PiCamera that sends an image to a message queue to have ML detect a person (or not) which then responds back to the client. The motion detection code is mostly lifted from pyimagesearch.com and is working well.

I now want to save video (including the original few frames) once I know a person is detected. Because of the delay in detecting a human (~3 secs) I plan on using a circularIO ring buffer to ensure I capture the initial few seconds of movement. This means I need to change how I loop through frames in detecting motion. Currently I am using:

rawCapture = PiRGBArray(camera, size=tuple(resolution))  camera = PiCamera()  for f in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):      frame = f.array      # resize, blur, grayscale frame etc.      # compare to average of last few frames to detect motion  

My understanding is this just grabs the Latest frame (ie. not every frame) and keeps on looping until motion is detected. This is what I want as I dont want the process to lag behind real-time by trying to check every frame.

To change this looping logic to leverage the ring buffer I think I can use something like this:

camera = PiCamera()  with camera:      ringbuf = picamera.PiCameraCircularIO(camera, seconds=60)      camera.start_recording(ringbuf, format='h264')          while True:              # HOW TO GET LATEST FRAME FROM ringbuf???              # resize, blur, grayscale frame etc.              # compare to average of last few frames to detect motion  

As indicated in the snippet above, how can I get the latest frame as a numpy array from ringbuf to perform by motion detection checking? I have seen examples that get every frame by adding motion_output=detect_function when start_recording is called, but this will check every frame and I dont want the process to lag behind real-time action.



from Recent Questions - Stack Overflow https://stackoverflow.com/questions/65375839/read-last-frame-from-picamera-ring-buffer Lee Melbourne http://ifttt.com/images/no_image_card.png

没有评论:

发表评论