Skip to content

CudaCamz runs on a Nvidia Jetson Nano giving your home or small office a bespoke well-filtered AI camera event generator & recording appliance on a budget.

License

Notifications You must be signed in to change notification settings

harrymao/CudaCamz

 
 

Repository files navigation

CudaCamz

Inspired by https://github.com/dusty-nv/jetson-inference/

Did this as a lockdown project.

The neighbourhood cats, dogs and other more interesting wildlife are now more transparent.

CudaCamz runs on a Nvidia Jetson Nano giving your home or small office a bespoke meaningfully-filtered AI camera event generator on a budget.

Can record all incoming video as well in case something goes down.

Uses an (optional) very network efficient RTSP proxy so that you can do the above and also live monitoring with something like VLC media player.

!

You will need some basic Linux skills and a bit of time looking at initial application output to prune false positives by adjusting these sections in the configuration file:

  1. [label_alarmlist] sets what events (a list of possibilities is here) need alarmed above the given confidence threshold. Examine your logfiles and/or database to see what is coming in.

  2. [label_percent_screenfill_min] states that a given event should only be considered if its percetage image area size is bigger than that given. I put this option in as certain types of leaves in the garden had the AI saying all sorts.

  3. [label_mutelist] says that you are not interested in those things (e.g. tennis rackets) period. Be prudent though, my favourite cat is often labelled as a bear, and not-so favourite cat a cow!

  4. [object_mutelist-] defines per camera areas where events are muted:

    _inside-cameraname (mute all events inside a defined area) : use for small things that repeatably generate false positives. For me that was a potted plant out front which AI said was a person at night.

    _outside-cameraname (mute all events outside, but also encapsulating, a defined area) : use for large things that do the same. For me, my front hedge became a dog as the sun began to set!

!

Example alarmed event

!

You also get an email and/or MQTT message for these if [smtp] and/or [mqtt] is configured in the configuration file. If you do not use, just delete those sections.

Samba is useful if you want to access events, images and video folders on the Jetson from a PC, but I tend to use WinSCP.

Important note

The first time CudaCamz is run using start.sh below, it will take five minutes or more for the AI model running on the GPU to be initially compiled.

After that on subsequent runs it will only take about thirty seconds to load from a cache.

Be patient!

Installing and running

Note that the script ./configure.py below creates start.sh and does other configuration work as well. You will need to re-run if cameras are added and/or image/video folders deleted.

  1. Put your camera URIs and image / video storage pathnames in the configuration file, then:
bash ./install-depends.sh

python3 ./configure.py ./config.txt

bash ./start.sh
  1. Examine the images folder / logfiles or sqlite database then tune the configuration file to remove any false positives you get.

  2. Then use this to start and stop CudaCamz:

./start.sh

./stop.sh
  1. If you delete an image or video folder, or add or delete a camera, things will need reconfigured again:
python3 ./configure.py ./config.txt
  1. Check the default values in rtsp-simple-server/rtsp-simple-server.yml.

These worked OK for me with 3 SD cameras.

However upping the camera resolution and framerate caused the proxy to run out of steam (got blank cameras sometimes when live monitoring). To test fix, I changed the values below in rtsp-simple-server/rtsp-simple-server.yml then re-ran start.sh. To make that change permanent, you need to change rtsp-simple-server/rtsp-simple-server.yml.original as well.

readBufferCount: 512 ->	readBufferCount: 4096 
protocols: [udp, tcp] -> protocols: [tcp]

Basic operational outline

For all cameras
	Get a frame
		Has any motion been detected in that frame ?
			Are there any unfiltered AI detection events in that frame ?
				Does any event in this frame meet any given alarm criteria ?
					Alarm (MQTT and SMTP email - as configured or not)

Performance and power plans

Three cameras attached at 720p, 20fps - Constant Bit Rate. Ambient temperature was 15C. No cooling. ai_resize_factor = 0.5 and motion_resize_factor = 0.25.

Measured using jtop.

Power plan mode Current AO temp (C) Total images processed per second
1 2.5A 52 2583
0 6.0A 66 1549

To change power plan mode on the Jetson Nano (and survive a reboot):

sudo nano /etc/nvpmodel.conf

change PM_CONFIG DEFAULT at bottom of that file to 1 - low power or 0 - high power

then

rm /var/lib/nvpmodel/status
sudo reboot

Example startup logfile

2021-03-08:19:19:43,355 INFO     [CudaCam.py:463] CudaCam started
2021-03-08:19:19:43,356 INFO     [CudaCam.py:469] Remapped rtsp:https://192.168.1.10:554/user=admin&password=secret&channel=1&stream=0.sdp to rtsp:https://127.0.0.1:8554/front_garden as using_rtsp_simple_proxy set
2021-03-08:19:19:43,356 INFO     [CudaCam.py:469] Remapped rtsp:https://192.168.1.12:554/user=admin&password=secret&channel=1&stream=0.sdp to rtsp:https://127.0.0.1:8554/back_garden as using_rtsp_simple_proxy set
2021-03-08:19:19:43,357 INFO     [CudaCam.py:469] Remapped rtsp:https://192.168.1.11:554/user=admin&password=secret&channel=1&stream=0.sdp to rtsp:https://127.0.0.1:8554/back_patio as using_rtsp_simple_proxy set
2021-03-08:19:19:46,892 INFO     [CudaCam.py:480] Starting inference engine, can take a while
2021-03-08:19:20:03,587 INFO     [CudaCam.py:482] Inference engine is up
2021-03-08:19:20:03,733 INFO     [CudaCam.py:517] Starting cameras and getting test images for /media/nano1/usbhdd/mutelist_reminder, can take a while
2021-03-08:19:20:14,936 INFO     [CudaCam.py:571] Processed 0 images in the past 10 seconds
2021-03-08:19:20:25,089 INFO     [CudaCam.py:571] Processed 320 images in the past 10 seconds
2021-03-08:19:21:22,700 INFO     [CudaCam.py:657] Event 'Initialised' : front_garden - person, confidence 0.54 : 211,286,13,247
2021-03-08:19:21:25,760 INFO     [CudaCam.py:657] Event 'Has moved' : front_garden - person, confidence 0.84 : 220,314,3,245
2021-03-08:19:21:25,969 INFO     [CudaCam.py:571] Processed 302 images in the past 10 seconds

Contributing

Have moved on to the next thing, so will shortly archive.

Please do email JoeTester1965 at mail dot com with any questions.

License

MIT

About

CudaCamz runs on a Nvidia Jetson Nano giving your home or small office a bespoke well-filtered AI camera event generator & recording appliance on a budget.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 79.5%
  • C++ 13.5%
  • Shell 7.0%