johnbradley / picameratraps

Raspberry Pi Camera Trap management software
MIT License
0 stars 0 forks source link

Synchronize capturing images on multiple camera traps #1

Open johnbradley opened 1 year ago

johnbradley commented 1 year ago

Evaluate different ways to capture multiple images in a way that will be synchronized across multiple camera traps.

johnbradley commented 1 year ago

One option is to capture multiple images is to have the camera traps all start taking pictures at the same time. If the camera traps are on WiFi they can synchronize their clocks before beginning the capture process. If all camera traps have a PiJuice module they can rely on the PiJuice RTC to set their time correctly.

Another option would be to have the cameras communicate over WiFi(or other means) and have one camera trap be responsible for sending a signal to take a picture.

johnbradley commented 1 year ago

Software to capture images:

johnbradley commented 1 year ago

I tested capturing 10 images in a row calling libcamera-still multiple times:

for i in {1..10}
do
   libcamera-still --datetime --nopreview
done

The above command took 1m26.777s to run.

$ ls -la --time-style=full-iso *.jpg
-rw-r--r-- 1 john john 983334 2023-09-16 13:29:20.159471743 -0400 0916132917.jpg
-rw-r--r-- 1 john john 983021 2023-09-16 13:29:28.819327593 -0400 0916132926.jpg
-rw-r--r-- 1 john john 978856 2023-09-16 13:29:37.459185255 -0400 0916132935.jpg
-rw-r--r-- 1 john john 982535 2023-09-16 13:29:46.139043718 -0400 0916132943.jpg
-rw-r--r-- 1 john john 977380 2023-09-16 13:29:54.768904427 -0400 0916132952.jpg
-rw-r--r-- 1 john john 972617 2023-09-16 13:30:03.458765583 -0400 0916133001.jpg
-rw-r--r-- 1 john john 971906 2023-09-16 13:30:12.148628133 -0400 0916133009.jpg
-rw-r--r-- 1 john john 968513 2023-09-16 13:30:20.868491590 -0400 0916133018.jpg
-rw-r--r-- 1 john john 967227 2023-09-16 13:30:29.548357024 -0400 0916133027.jpg
-rw-r--r-- 1 john john 964620 2023-09-16 13:30:38.248223474 -0400 0916133036.jpg

It seems to take 8 or 9 seconds for each image captured when running this way.

johnbradley commented 1 year ago

Next I tried using the --timelapse feature with libcamera-still.

libcamera-still --timeout 60000 --timelapse 5000 --datetime --nopreview

This took 1m0.762s to run creating 11 images.

ls -la --time-style=full-iso *.jpg
-rw-r--r-- 1 john john 939179 2023-09-16 13:39:36.861812379 -0400 0916133934.jpg
-rw-r--r-- 1 john john 937910 2023-09-16 13:39:41.911764371 -0400 0916133939.jpg
-rw-r--r-- 1 john john 939665 2023-09-16 13:39:46.991716232 -0400 0916133944.jpg
-rw-r--r-- 1 john john 944225 2023-09-16 13:39:51.951669376 -0400 0916133949.jpg
-rw-r--r-- 1 john john 946022 2023-09-16 13:39:57.001621819 -0400 0916133954.jpg
-rw-r--r-- 1 john john 946624 2023-09-16 13:40:02.051574409 -0400 0916133959.jpg
-rw-r--r-- 1 john john 949862 2023-09-16 13:40:07.041527706 -0400 0916134004.jpg
-rw-r--r-- 1 john john 950391 2023-09-16 13:40:12.021481237 -0400 0916134009.jpg
-rw-r--r-- 1 john john 951331 2023-09-16 13:40:17.031434630 -0400 0916134014.jpg
-rw-r--r-- 1 john john 955716 2023-09-16 13:40:22.091387700 -0400 0916134019.jpg
-rw-r--r-- 1 john john 957521 2023-09-16 13:40:27.121341187 -0400 0916134024.jpg

This seems pretty accurate. Less than 5 seconds didn't achieve consistent times between captures. Testing 5 second timelapse achieved similarly accurate results.

johnbradley commented 1 year ago

Since libcamera-still is c++ and is getting pretty accurate time wise results I am inclined to use it instead of picamera2 for now. The picamera2 python package doesn't have a timelapse feature built in.

johnbradley commented 1 year ago

I tested out running a 3 hour timelapse taking pictures every 10 seconds with libcamera-still.

nohup libcamera-still --timeout 10800000 --timelapse 10000 --datetime &

This ran fine for the entire time and finished without error. It created 1078 images at 4608 × 2592. I expected 1080 images. The total size of all images was 962M.

I looked at the output files to determine why we had 2 less images than expected. The first image recorded was at 15:56:34.802018. The last image recorded was at 18:56:22.906982. The inital setup time is probably subtracted from the total timeout. Perhaps I should add timelapse value to timeout. There were 6 images that took longer that 10.2 seconds or < 9.8:

16:09:56.223406 1900-01-01 16:10:08.013281 11.789875
16:10:08.013281 1900-01-01 16:10:16.233194 8.219913
16:57:01.113962 1900-01-01 16:57:11.543854 10.429892
16:57:11.543854 1900-01-01 16:57:21.133754 9.5899
18:40:31.373020 1900-01-01 18:40:42.112985 10.739965
18:40:42.112985 1900-01-01 18:40:51.302955 9.18997
johnbradley commented 1 year ago

I should have used --nopreview in the 3 hour test. Without this flag the pi will attempt to display each image on the monitor attached to the HDMI port.