{"id":18607758,"url":"https://github.com/cfries/surveillance-camera","last_synced_at":"2025-09-23T16:05:28.747Z","repository":{"id":77717082,"uuid":"357139866","full_name":"cfries/surveillance-camera","owner":"cfries","description":"Small project to find similar images in a directory. Experimental. For my own use only.","archived":false,"fork":false,"pushed_at":"2021-05-02T10:01:50.000Z","size":1436,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-09T14:05:31.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cfries.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-12T09:49:12.000Z","updated_at":"2021-05-02T10:01:52.000Z","dependencies_parsed_at":"2023-03-14T04:16:48.544Z","dependency_job_id":null,"html_url":"https://github.com/cfries/surveillance-camera","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cfries/surveillance-camera","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfries%2Fsurveillance-camera","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfries%2Fsurveillance-camera/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfries%2Fsurveillance-camera/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfries%2Fsurveillance-camera/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cfries","download_url":"https://codeload.github.com/cfries/surveillance-camera/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cfries%2Fsurveillance-camera/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276604110,"owners_count":25671759,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T02:31:09.804Z","updated_at":"2025-09-23T16:05:28.700Z","avatar_url":"https://github.com/cfries.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"Surveillance Camera Project (for Raspberry Pi)\n==========\n\n****************************************\n\n**Small project with some Java code that may be used to build a simple but effective Surveillance Camera**.\n\n****************************************\n\n**Experimental. For my personal use only.**\n\n# Application\n\nThe project currently contains two classes that provide a `main`-method that can be run (a `mvnw` script is provided, and you may use Maven exec, see below).\n\nThe project has two remarkable properties:\n\n- it transfers the picture to a network storage, so removing or destroying the pi will not delete images already taken.\n- it transfers the picture only if a change is detected to reduce resource consumption (network bandwidth, storage space on the NAS).\n\nA disadvantage of the tool is that is does not allow to take images in very short succession since the comparison requires approximately 0.5 seconds on a Raspberry Pi.\nIt currently takes approximately 1 image per second.\n\n## TakePictureUponChange\n\nThe class `TakePictureUponChange` runs a script (using `ProcessBuilder`) which launches a command to take a picture.\nIt then compares this picture with a previous one and pushes\nthe image to a NAS if a change is detected. In any case, the picture on the pi will be deleted afterwards.\n\nThe program requires four command-line options, in this order:\n\n- `threshold`: a floating-point number between 0 and 1 determining when a picture is considered to be different. You can see it as a percentage value. A good value is 0.018.\n- `filenamePrefix`: a prefix for the name of the image. The image will be stored under `filenamePrefix-timeStamp.jpg`.\n- `targetDir`: the directory to be used to store the image. The image will be moved to this directory if it is the first one that is taken or if the image is different from the previous image by more than `threshold`.\n- `imageCommand`: the shell command to be used to take the image. Use the placeholder `{filename}` for a filename under which the image is stored in the working directory of the program.\n\n### Running this project out of the box\n\nAssuming a NAS is mounted under `/Volumes/nas` (see below) and there is a folder `piimages`, so the\npath `/Volumes/nas/piimages` exits, then the following will take a picture approximately every second and - if it\ndetects changes in the image, it will transfer it to the NAS.\n\n```\n./mvnw clean install exec:java -Dexec.mainClass=com.christianfries.surveillancecamera.TakePictureUponChange -Dexec.args=\"0.018 image /Volumes/nas/piimages \\\"raspistill -th none -q 10 -t 400 -awb greyworld -o {filename}\\\"\"\n```\n\nRemark: The argument `-t 400` adds a timeout of 400 milliseconds. However, launching the app adds some more milliseconds, so\nin summary, it will take a picture every 700-1000 milliseconds. The Java process runs the image comparison in parallel,\nbut it requires approximately 600 milliseconds to process the image (on a Pi 3B). So you have to be careful when choosing the\ntimeout parameter smaller.\n\nThe process of transferring the image is also running in a different thread. If images cannot be transfered fast enough they\nwill accumulate on the Pi's local memory.\n\n## ImagePrune\n\nThis is a standalone version of the image comparisson operating on a given folder and deleting all images in the sequence that are too similar.\n\nThe program requires two command-line options, in this order:\n\n- `sourceDir`: the directory to be scanned for images.\n- `threshold`: a floating-point number between 0 and 1 determining when a picture is considered to be different. You can see it as a percentage value. A good value is 0.018.\n\n**WARNING:** *Be aware that the program deletes images that are considered to be duplicates!*\n\n## Useful stuff\n\nBelow you find some stuff that allows you to build the surveillance system with a Pi such that\n\n- The Pi ill launch the script in the background once it is powered up.\n- The Pi will wait for a WLAN network.\n- The Pi will mount an AFP network drive.\n- The Pi will run this app.\n\n### Mounting AFP Network Drive on Raspberry Pi\n\n#### Installing AFP Support (once)\n\n```\nsudo apt-get install afpfs-ng -y\nsudo apt-get install fuse -y\nsudo mkdir -p /Volumes/nameOfTheVolume\nsudo chown pi:pi /Volumes/nameOfTheVolume\n```\n\n#### Mounting a Volume\n\n```\nafp_client mount -u userNameOnServer -p passwordOnServer ipAddressOfServer:nameOfTheVolume /Volumes/nameOfTheVolume\n```\n\n### Waiting for WLAN to be available\n\n```\nwhile [ \"$(ifconfig wlan0 | grep inet | grep 192.168.)\" = \"\" ];  do sleep 1; done\n```\n\n### Running a script upon startup of pi.\n\nCopy the script (assuming its name is `nameOfScript`) to `/etc/init.d`. Then run\n\n```\nsudo update-rc.d nameOfScript defaults\n```\n\n### Taking Pictures in a Loop, Storing them with a Timestamp\n\n```\n#!/bin/bash\n\nfor(( ; ; ))\ndo\n  timestamp=$(date +%s)\n  raspistill -th none -q 10 -t 1000 -o /Volumes/nameOfVolume/nameOfDirectory/image-$timestamp.jpg\ndone\n```\n\n### Full script\n\nThe following script\n\n1. waits for the WLAN to get connected\n2. mounts a NAS\n3. checks out this project\n4. runs `TakePictureUponChangeTakePictureUponChange`\n\n** WARNING: If you use this script, you should use it with your own fork of this repository to be sure what code will be run and to be sure that a future version will not break your system. Note that a script that is launched via /etc/inid.d runs under the root account!**\n\n```\n#!/bin/bash\n\n# wait for wlan\nwhile [ \"$(ifconfig wlan0 | grep inet | grep 192.168.)\" = \"\" ];  do sleep 1; done\n\nsleep 10\n\n# mount nas\nafp_client mount -u USERNAME -p PASSWIRD \"SERVER:SHARE\" /Volumes/nas\n\nmkdir -p /tmp/image-recorder\ncd /tmp/image-recorder\n\ngit clone https://github.com/cfries/surveillance-camera.git\ncd surveillance-camera\ngit pull\n\n./mvnw clean install exec:java -Dexec.mainClass=com.christianfries.surveillancecamera.TakePictureUponChange -Dexec.args=\"0.018 image /Volumes/nas/piimages \\\"raspistill -th none -q 10 -t 400 -awb greyworld -o {filename}\\\"\"\n```\n\n# Hardware\n\nThe following hardware may be useful:\n\n## Power Supply\n\nIt is possibly to power the Raspberry Pi though an outdoor lamp (modifications YOUR OWN RISK!).\n\nThe (European) Apple Power Plug has a useful feature. You can remove the part that goes into the socket and replace it with a conventional Euro C7 Power Cable. \n\n![Power Plug](/img/ApplePowerPlugiPad.png)\n\nThen you can cut the cable and connect it - ON YOUR OWN RISK - to a power source (e.g. an insulating screw joint that is part of an outdoor lamp). \n\n![Cable C7](/img/CableC7.png)\n\nIf the outdoor lamp has an indoor switch, the system can be switched on an off from inside.\n\n## Parts\n\n- Raspberry Pi 3B (approx. 40 €) \n- Raspberry Pi Camera (approx. 20 € to 30 €)\n- Raspberry Pi Housing (approx. 10 €)\n- USB Cable (Raspberry Pi to USB power adapter) (approx. 3 €)\n- Apple 12 W USB power adapter (approx. 20 €)\n- C7 Cable (USB power adapter to power source) (approx. 3 €)\n\nThe total is approx. 100 €. Of course you may still run other stuff on the Pi.\n\nThe project can also be realized with a Pi Zero, which makes it 20 € cheaper.\n\nLicense\n-------\n\nThe code of package \"com.christianfries.clustering\" is distributed under the [Apache License version\n2.0][], unless otherwise explicitly stated.\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcfries%2Fsurveillance-camera","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcfries%2Fsurveillance-camera","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcfries%2Fsurveillance-camera/lists"}