Skip to content

Matthias-Wandel/imgcomp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What Imgcomp does

Imgcomp makes motion triggered timelapses using a Raspberry Pi and camera module.

It serves a similar purpose as the software "motioneye", but operates on still frames instead of video. This makes for much better image detail, but frame rate is limited to about 4 frames per second, depending on Raspberry Pi camera module version. I typically use it at just 1 frame per second.

Images are initially captured to ramdisk to minimize flash wear, then analyzed and if significant changes detected, saved to flash.

Setting up

Setting up is done by cloning the repository onto your raspberry pi and running the setup scripts from the setup directory. these compile the code base and make necessary configuration changes to crontab (for starting it) and apache2 (for browsing images)

Please see setup/setting_up.txt for how to set up. Setup scripts are in the setup directory.

Also see config.md for the configuration options.

Directory structure used by imgcomp:

~/imgcomp/... where imgcomp source files live.
~/imgcomp.conf configuration file, imgcomp should run in this directory (typing imgcomp/imgcomp to run)
~/images/ Root directory for where the images go.
~/images/200204/ Root for pictures of Feb 4 2020 (one dir for each day, named YYMMDD
~/images/200204/13/ Pictures for 1 pm to 2 pm for Feb 4 2020
~/images/200204/13/0204-131445 0494.jpg  Picture taken Feb 4 2020 at 13:14:45, change level 494
~/images/saved/ Where picture are hard linked to when "saved" from image browser. One directory for each month.
 
~/www web root
~/www/view.cgi view.cgi is dropped here on compiling viewing program
~/www/realtime.html
~/www/wait_change.cgi
~/www/showpic.js Also dropped here on compiling viewing program
~/www/pix/ links to ../../images (softlink)
~/www/browse.conf configuration file, used for setting local holidays

Note that imgcomp can be configured for different directory structures, but the html browser must use the above directory structure.

Imgcomp program

To use imgcomp, you must compile it.
There are sample configuration files in imgcomp/conf-examples Imgcomp uses libcamera-still, raspistill or libcamera-vid to dump jpeg files into /ramdisk (which is a ram disk the setup creates) As images are aquired, it reads and compares these files, copies them to ~/saved/.... if they contain relevant changes.

In the video mode hack, it looks for video files in /ramdisk/vid and uses ffmpeg to extract stills to /ramdisk/tmp then uses those files as input. But if you want video, look for the project "motionpi" by a different author.


Browsing program

Browsing by hour

The browsing program is what makes viewing the oputput from the aqusition program fun. You don't have to go through video clisp to see what happened. Just hover over the bargraphs for the times, to see what happened, clcik on the bars to navigate there, and drag across the image left or right to scrub forward or backwards though the qauired images.

Browsing by day

The browse program assumes images are stored in the www directory under "pix", as configured by the setup script.

There is a directory for each day, therein a directory for each hour. For example, the pictures from noon to 1 pm to 2 pm on Jun 2023 would be in
      ~/www/pix/230604/13

Files in each directory are expected to be named like this:

      0504-130000 0002.jpg
      0504-130809 0002.jpg
      0504-130810 0941.jpg
      0504-130811 2102.jpg
      .....
      Log.html

Names are MMDD-HHMMSS LLLL Where M is Month, D is Day, H is Hour, M is minute S is second, and L is the detected image change level. Imgcomp creates this directory structure to store its files as it saves them.

The main viewing program is "view.cgi", which does most of the work. There is also the "tb.cgi" which is used to generate thumbnails on the fly, very fast using libjpeg's built in undersampling.

wait_change.cgi is used for realtime.html to wait for a significant enough change.

showpic.js is the javascript code for flipping through the images.

Local holidays can be set in the browse.conf file in the format YYMMDD. There is a sample configuration file in imgcomp/conf-examples.

How motion detection works

Imgcomp runs the raspberry pi camera capture program "libcamera-still" or "raspistill" to capture still jpeg images every second. With burst mode (-bm option in raspistill), up to 4 images can be captured per second, depending on camera model. Images could potentially come from different sources. I have experimented with using a webcam to capture still images, but didn't find a sufficiently reliable still image capture solution to use with webcams. My brother uses it with images captured from RTSP cameras

Imgcomp tries to differentiate between important and unimportant changes. Imgcomp looks for localized changes in the image from one image to the next. Imgcomp also has the ability to ignore or emphasize specified regions during comparison using the diffmap feature. Imgcomp also has a "motion fatigue" feature that makes it ignore changes in parts of an image that are changing a lot over time. This feature is used to avoid triggering too often on things swaying in the wind.

License

imgcomp is licensed under the GPL version 2 (not version 3) For details, please see here:
http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details (docs/license.txt)