Comments (4)
I should add some bits to the advanced recipes section in the docs for this as I suspect it's going to be a common question! In the meantime, here's a quick couple of (untested and incomplete!) examples in a gist covering the topic: https://gist.github.com/waveform80/8496879
If you can let me know if there's any errors in the code posted (other than the obvious omission of an actual motion detection algorithm!), I'd be most grateful. Then I can tidy them up as much as possible and add them to the docs.
from picamera.
Hi Dave
I slightly modified your example: https://gist.github.com/mjmare/8503306
With the original example and with the modified one I get the following error at random moments. I may get one or more video files before the error occurs.
ssh://[email protected]:22/usr/bin/python -u /home/pi/picam/testcircular.py
Motion detected
No motion
No motion
No motion
No motion
Traceback (most recent call last):
File "/home/pi/picam/testcircular.py", line 50, in
main(camera)
File "/home/pi/picam/testcircular.py", line 36, in main
if detect_motion(camera):
File "/home/pi/picam/testcircular.py", line 6, in detect_motion
camera.capture(stream, format='jpeg', use_video_port=True)
File "/usr/local/lib/python2.7/dist-packages/picamera/camera.py", line 859, in capture
if not encoder.wait(30):
File "/usr/local/lib/python2.7/dist-packages/picamera/encoders.py", line 326, in wait
raise self.exception
picamera.exc.PiCameraError: Unable to return a buffer to the encoder port: Argument is invalid
Process finished with exit code 1
As a side note: currently the example records 10 video when motion is detected. It then stops for a second and starts looking for motion. This wonβt fly in more realistic motion detection scenarios.
In the simplest case one needs 2 images to detect motion. But now the previous image is 10 secs old. One could of course get two new images but that makes the video interruption even longer (if motion is still present).
Even worse: if you want to implement more robust motion detection techniques like segmentation one needs dozens of images (to filter out background fluctuations).
So what is needed is to continuously detect motion by capturing and processing images. If motion is detected: start video capture (up to N seconds). If motion is again detected while recording video: keep recording video. If not motion is detected , stop recording after M seconds after last motion.
The reason for distinct, but contiguous video segments is to keep file size manageable and to enable parallel uploads to a server.
Iβm telling you all this, not for you to solve my problems but to hopefully give you a better understanding of my particular use case.
Thanks again
Marcel
On 18 Jan 2014, at 22:39, Dave Jones [email protected] wrote:
I should add some bits to the advanced recipes section in the docs for this as I suspect it's going to be a common question! In the meantime, here's a quick couple of (untested and incomplete!) examples in a gist covering the topic: https://gist.github.com/waveform80/8496879
If you can let me know if there's any errors in the code posted (other than the obvious omission of an actual motion detection algorithm!), I'd be most grateful. Then I can tidy them up as much as possible and add them to the docs.
β
Reply to this email directly or view it on GitHub.
from picamera.
The exception you're encountering looks like #40 - I'm currently working on a fix for that (I think I've found the root cause; it's an odd one as I think it's been there all along, but something in 1.0's timing changed to cause the race condition to manifest).
Anyway, to the examples: the first example is deliberately simplistic (altering it to work with two pictures should be trivial, but working around the issue with continual recording while detecting motion isn't due to the limited size of the circular buffer). The second example is easier to manipulate to cover your needs:
- Watch for motion
- When motion is detected, split recording to disk (the "after" file)
- While recording to disk, write the prior 10 seconds from the circular buffer to disk as well (the "before" file), and wipe the circular buffer
- Continue recording to disk until motion is not detected for, say, 10 seconds
- Once this is satisfied, split recording back to the circular memory buffer
The existing example already does all of this, except for point 4 - which is a relatively trivial change. I've updated the original gist to cover this now (I also renamed the files in the gist as I'm intending one to become the example for circular recording in the "basic recipes" section, and the other to become the example in the "advanced recipes" section). The advanced example also demonstrates a crude method for capturing two images (though actual comparison is still left as an exercise for the reader).
from picamera.
Marking this as an enhancement issue for the docs - integrate the gists for 1.1
from picamera.
Related Issues (20)
- python3-picamera package depends on python3-numpy
- What is the default intra-frame period? HOT 2
- Limited running time HOT 1
- Not supported in bullseye Raspberry Pi OS version HOT 3
- Jumping exposure time on Raspberry Pi HQ camera HOT 1
- [Docmentation] How to find out the Bayer pattern from the CFA layout HOT 2
- Can one access both frames from the OPQV-dual stream and output the difference in real time? HOT 2
- libmmal.so: cannot open shared object file: No such file or directory HOT 6
- Frame freezes whilst try display/save high resolution frame HOT 1
- shutter_speed TypeError HOT 12
- Cannot install on development machine
- No such file or directory HOT 1
- PiCamera start_preview blocks indefinitely
- Realtime Motion Detection Latency
- Camera eposure time doubled from shutter speed?
- Is the `PiBayerArray.flush` method unpacking data correctly?
- 4.16. Raw Bayer data captures - Example Code - Assertion Error
- mjk
- stereo mode: how to switch camera sides HOT 2
- Error : OSError: libbcm_host.so: cannot open shared object file: No such file or directory HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from picamera.