Replies: 16 comments 70 replies
-
Hello, Why not. However, I need to get my hand on the hardware (which should not take too much time). Also, don't forget that we are messing with I don't exactly know how much time it can take, so… we'll see. |
Beta Was this translation helpful? Give feedback.
-
I would be glad to join the effort for this and for the Pi Camera v3 (gotta buy one or two) I am an old hand at development, but kinda new to Python applications. I did my work in C and C++ Let me know, please. |
Beta Was this translation helpful? Give feedback.
-
Since starting this thread, picamera2 has evolved a bit. They now have an example which could be helpful to us. I'm keen to also explore if we can do similar motion detection without OpenCV. I'll play around and report back. |
Beta Was this translation helpful? Give feedback.
-
Over the last week I've been gradually working my way through the code in this project and updating it to work with Picamera2 (libcamera) and the Pi Camera Module 3. I've reached the point where everything now seems to be working fine, but I do need to run it for a week or so with it capturing before I'm happy there are no memory leaks or other bugs that haven't been picked up in my testing so far. At that point I'll make a pull request. I have added a number of new features, as follows: Option to switch between two resolutions on the web interface (1640x1232 and 1920x1080). MP4Box no longer seems to exist so I've changed the code to use ffmpeg instead, so that will need installing first. My testing on a Pi Zero 2W with the camera module 3 has shown that using framerates above 20 cause the Pi to eventually lock up, so I've set this to 20 in the config.json file. If anyone else wants to test the new code, my fork is located at https://github.com/caracoluk/NaturewatchCameraServer/ and it's commit 36a3103. I'll confirm in a week or so if my testing has been successful. |
Beta Was this translation helpful? Give feedback.
-
Mind sending them over?
…On Tue, Jun 18, 2024 at 4:19 AM caracoluk ***@***.***> wrote:
@gschivley <https://github.com/gschivley> if you have problems running
the workflow steps for some reason and want to get a test set up in time
for the summer break, then let me know as I have a full set of build
instructions that I used to build from a fresh install of PiOS Lite
BookWorm that I could send over.
—
Reply to this email directly, view it on GitHub
<#111 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACPERVC26LKUWB6BT7J4EUDZH7USDAVCNFSM6AAAAAAZXDSUZOVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TQMBTGMZTA>
.
You are receiving this because you were mentioned.Message ID:
<interactionresearchstudio/NaturewatchCameraServer/repo-discussions/111/comments/9803330
@github.com>
|
Beta Was this translation helpful? Give feedback.
-
Could you upload them as a GitHub gist or something so we could all have a try please?
Sent from Outlook for iOS<https://aka.ms/o0ukef>
…________________________________
From: caracoluk ***@***.***>
Sent: Tuesday, June 18, 2024 11:53:14 AM
To: interactionresearchstudio/NaturewatchCameraServer ***@***.***>
Cc: chrismelikian ***@***.***>; Mention ***@***.***>
Subject: Re: [interactionresearchstudio/NaturewatchCameraServer] Looking for help: transitioning to picamera2 (Discussion #111)
Sure, might be easier if you let me know your email address and I'll send them over that way.
—
Reply to this email directly, view it on GitHub<#111 (reply in thread)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABBNBDQLW23PFLTZIHVCYATZIAGRVAVCNFSM6AAAAAAZXDSUZOVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TQMBUHA4DS>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
For those wanting to test the updated code while we await the Pull Request testing, here are the steps required to build from scratch: Install latest version of Raspbian Bookworm (June 2024) onto your Pi Zero W/Zero 2W Add these commands to /boot/firmware/config.txt: Update Pi to latest sw/fw: Install extra packages: Clone the NatureWatch git repository: Install NatureWatch service: Note that this won't set up the MyNatureWatch WiFi, but everything else should be functional. |
Beta Was this translation helpful? Give feedback.
-
I think it does take a while to install opencv-python-headless. I triggered the installation and went to get some lunch. When I came back an hour later it had finished so I don’t know exactly how long it took. I do recall it taking a while to install from previous projects however.On 22 Jun 2024, at 16:39, Greg Schivley ***@***.***> wrote:
How long did it take you to install all the dependencies? opencv-python-headless seems to be an especially slow one.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi Vincent,
The instructions were really intended as a quick means of testing the code rather than a recommended way of building the configuration. They were the process I followed to get to the point where I could start working on the code however. That’s useful information about the use of a venv and not something I’ve come across before. The use of opencv-python-headless was taken from the original build script and I simply copied that when installing the necessary modules.
As for installing nodejs and compiling, I did perform those tasks on my system but left them off of the instructions as I’d included the compiled project on the GitHub repository. The main repository didn’t have the compiled project in the build directory so I was expecting the compilation to replace those when the install script runs.
I’ve a feeling the /home/pi references might have been left in by accident when I was replacing mp4box with ffmpeg. That shouldn’t be a problem to resolve.
|
Beta Was this translation helpful? Give feedback.
-
Thanks @caracoluk for submitting your pull request, and for all the work you've put into this so far! A few points to hopefully clear things up:
In order to deploy this for real, we'd need to get it working with CustomPiOS and our GitHub workflow, as this is how we keep consistency with the OS setup. It sounds like there's a bit of work to get this to a deployable state. I suggest we merge this pull request into a new dev branch, where we can work together to make the necessary changes for deploying this. |
Beta Was this translation helpful? Give feedback.
-
I think I might have found an issue. On my Pi Zero 2W I've found that the circular buffer seems to hang every so often. Sometimes it can be after a few hours, other time it can go several days. As far as I can tell it's not a problem with the code and I'm wondering if it might be a bug in the kernel/camera drivers. When it happens, the web interface appears to work but the lores feed has frozen and attempts to call /api/settings also hangs. There is nothing in journalctl for the python.naturewatch.service of any interest, but shortly afterwards messages such as the following are logged in dmesg:
and
I've been consistently ruling out possible causes, and have so far eliminated the following:
I'm currently testing a lower framerate of 15fps to see if that prevents the problem. I've attached a gdb python debugger to the code when it's in this state and the most recent call when it's hung is in the ChangeDetector class at the following point:
That was originally a sleep of 0.02 seconds and I increased it to 0.03 to see if that helped since a frame rate of 20fps would allow for a sleep of 0.05 seconds and I wondered if perhaps we're asking for frames too quickly. So, after testing the lower frame-rate I'll increase this value again to see if that has any effect. In the meantime, I'd be grateful if others could try running the latest code and leave it running in video capture mode for at least several days as it would be good to know if it's an issue with my hardware. |
Beta Was this translation helpful? Give feedback.
-
I was carrying out some performance testing over the weekend, attempting to obtain better video frame rates. I explored setting NoiseReductionMode in PiCamera2 to either "Off" or "Fast" and also changing the H264 encoder quality from "Quality.HIGH" to "Quality.MEDIUM". These changes made negligible difference to frame rate so I didn't change them. I also tested writing the initial H264 file to a memory buffer rather than straight to the SD card. This didn't really help either so I left it saving straight to SD card. What did make a very noticeable improvement was setting the video output format to YUV420 instead of RGB888. With that change the Pi Zero 2W will happily run at 25fps, most likely higher but on my Pi that pushes the CPU temperature above 80C so I'm leaving the default at 20fps for the time being and it can be changed in the config.json file if necessary. I've also added a check in ChangeDetector.py as there's no point in running the motion detection function if a video is in the process of being saved. Saving those CPU cycles does help push up the frame rate by reducing the number of dropped frames. In a similar fashion, the same check is being performed in CameraController.py so if a video is being recorded the video stream on the web page is only updated once a second, instead of every 0.03s. Once the recording is complete the values are returned back to 0.03s. I think performance is no longer an issue on a Pi Zero 2W, but even with these changes I couldn't quite get 15fps out of my Pi Zero W. It can just about manage 12fps, but any more than that and frames are dropped. Once the motion is detected, and the motion detection routine is temporarily disabled, the Pi Zero W can manage 15fps, but the problem is the contents of the 5s buffer before motion is detected. While that was being filled with motion detection enabled, the Pi Zero W can't write frames at 15fps, only managing 10-12fps. This means that it takes longer than 5s buffer to fill the buffer. When the buffer is written to the SD card, instead of containing 5s of data, it has about several extra seconds. This is a problem because ffmpeg expects a consistent 15fps when it converts the H264 file to an mp4. The end result is that the MP4 file contains about 19s of content instead of 15s. So, those 19s play back in 15s which obviously doesn't look correct. Perhaps we should simply release the new web app wit the caveat that it's designed for the Pi Zero 2W, though will work on the Pi Zero if the frame rate is set to 10-12fps. I have this morning committed these changes. |
Beta Was this translation helpful? Give feedback.
-
This morning I've updated the watchdog script (/helpers/watchdog.sh) so that it now checks every 5 minutes if the service is responding properly. Each time the check is run it monitors the state of the capture mode (inactive/photo/video/timelapse). If the service stops responding, it restarts and then re-enables the last capture mode detected. I've updated the installer scripts to schedule the watchdog to run at each boot. I don't like having to rely on a watchdog script, but after spending weeks trying to work out why the service hangs intermittently after a few days I feel like it's time to settle for this approach instead. I'll leave my two Pi Zero 2W running for at least the next few weeks, but I think we at least now have something that can be considered for deployment. |
Beta Was this translation helpful? Give feedback.
-
Now that both of my Pi Zero 2Ws have been left running for 10 days I'm happy to say that both have remained running. One Pi has remained running for the full 10 days without the service hanging at all. That's further confirmation that the recent code change has made things much more stable. The app hung twice on the other Pi over the course of the 10 days, but on each occasion the watchdog detected the hang, restarted the service and restarted the video captures. Therefore I'm happy the code is now stable. |
Beta Was this translation helpful? Give feedback.
-
Hello, what's the current status please? Is it possible to try out the latest version to support the Pi Camera 3 on a Pi Zero2W please? |
Beta Was this translation helpful? Give feedback.
-
It’s in a fully working state and the code is in a finished state. There’s a firmware bug that is partially fixed by applying the latest Pi kernel update, but since there is a watchdog automatically restarting the service if it fails that should not matter. I’ve been running the latest code on two of my Pi zero 2Ws for the last few months and they’re running fine.
The only thing to keep in mind is that the latest code is not packaged up for distribution yet so you would need to follow the steps described in the comments above to set it up yourself.
|
Beta Was this translation helpful? Give feedback.
-
Hi everyone,
We're looking for people to help us transition My Naturewatch to picamera2 and libcamera. Unfortunately we don't have funding to work on this project actively, but do have a little bit of time to do code reviews and coordinate this. We are looking for contributors who are willing to give some of their time to transition the codebase to picamera2.
In particular, the CameraController class will need to work with picamera2. Photos should be easy, but video may be a challenge, as we use circular recording to capture the action before the camera was triggered.
Let me know if I can help in any way. To our lovely contributors so far (@egueli, @frak, @raphaelcoeffic, @HAZET, @Vincent-Stragier, @MrChaz, @Gadgetoid), thank you for all your contributions, and I hope some of you may have some time to donate to this. We and the My Naturewatch Camera community will be so grateful!
Beta Was this translation helpful? Give feedback.
All reactions