Skip to content

Commit

Permalink
Allow support for manual focus cameras and fix logic issue with image…
Browse files Browse the repository at this point in the history
… analysis.
  • Loading branch information
eat-sleep-code committed Feb 5, 2024
1 parent 3fdf017 commit 997390d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ awb_auto_is_greyworld=1
---

> [!TIP]
> If you are using a Raspberry Pi with 1GB – or less – of memory, you may wish to increase your SWAP file to match your memory size as outlined in this [third-party guide](https://pimylifeup.com/raspberry-pi-swap-file/).
---

> [!IMPORTANT]
> *This application was developed using a Raspberry Pi V3 12MP (2023) camera and a Raspberry Pi Zero 2 W board. This application should also work without issue with Raspberry Pi 5 boards, Raspberry Pi 4B boards and Raspberry Pi HQ (2020) cameras. Issues may arise if you are using either third party or older hardware.*
> *This application was developed using a Raspberry Pi V3 12MP (2023) camera and a Raspberry Pi Zero 2 W board. This application should also work without issue with Raspberry Pi 5, Raspberry Pi 4B, Raspberry Pi 3B and 3A, and Raspberry Pi Zero W boards. This application should also work with Raspberry Pi HQ (2020) cameras. Issues may arise if you are using either third party or older hardware.*
40 changes: 23 additions & 17 deletions camera.timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import threading
import time

version = '2024.02.03'
version = '2024.02.05'


# Kill other camera script(s)
Expand All @@ -34,8 +34,12 @@
camera = Picamera2()
camera.set_logging(Picamera2.ERROR)
stillConfiguration = camera.create_still_configuration(main={"size": (1920, 1080)})
camera.set_controls({"AfMode": controls.AfModeEnum.Continuous})

try:
camera.set_controls({"AfMode": controls.AfModeEnum.Continuous})
except Exception as ex:
console.info('Camera does not support autofocus.')
time.sleep(3)
pass

# === Argument Handling ========================================================

Expand Down Expand Up @@ -272,6 +276,8 @@ def analyzeLastImages():
global interval
global framerate
global waitUntilAnalysisStatus
global darknessThreshold
global brightnessThreshold

try:
time.sleep(interval * 1.5)
Expand Down Expand Up @@ -308,20 +314,20 @@ def analyzeLastImages():
console.info('Exiting long exposure mode based on analysis of last image set... ')
camera.framerate = 30

if measuredAverageBrightness > (brightnessThreshold + 25) and measuredAverageBrightness > -1:
if camera.shutter_speed == 0 or camera.shutter_speed > 1000:
console.info('Increasing shutter speed based on analysis of last image set... [1000]')
camera.shutter_speed = 1000
elif camera.shutter_speed > 100:
console.info('Increasing shutter speed based on analysis of last image set... [50]')
camera.shutter_speed = 50
elif measuredAverageBrightness < (brightnessThreshold - 25):
if camera.shutter_speed < 100 and camera.shutter_speed != 0:
console.info('Decreasing shutter speed based on analysis of last image set... [1000]')
camera.shutter_speed = 1000
elif camera.shutter_speed > 900:
console.info('Setting shutter speed to "auto" based on analysis of last image set... ')
camera.shutter_speed = 0 # Auto
if measuredAverageBrightness > (brightnessThreshold + 25) and measuredAverageBrightness > -1:
if camera.shutter_speed == 0 or camera.shutter_speed > 1000:
console.info('Increasing shutter speed based on analysis of last image set... [1000]')
camera.shutter_speed = 1000
elif camera.shutter_speed > 100:
console.info('Increasing shutter speed based on analysis of last image set... [50]')
camera.shutter_speed = 50
elif measuredAverageBrightness < (brightnessThreshold - 25):
if camera.shutter_speed < 100 and camera.shutter_speed != 0:
console.info('Decreasing shutter speed based on analysis of last image set... [1000]')
camera.shutter_speed = 1000
elif camera.shutter_speed > 900:
console.info('Setting shutter speed to "auto" based on analysis of last image set... ')
camera.shutter_speed = 0 # Auto

measuredBrightnessList.clear()

Expand Down

0 comments on commit 997390d

Please sign in to comment.