Skip to content

Commit

Permalink
Add full-range autofocus option
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Jessop authored and Mark Jessop committed Dec 23, 2024
1 parent 63f9907 commit 012dc01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion start_tx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ sleep 10
# Set a fixed lens offset for the PiCam v3, in dioptres. May help with autofocus in cold temperatures.
# The PiCam v3 can be offset by a maximum of -3 dioptres before hitting a hard-stop
# Set this to -99.0 to set the PiCam v3 to use the entire lens travel range.
# The modified focus mapping will be printed out on startup.
# e.g. to offset by 1 dioptre:
# --afoffset -1.0 \
#
# Use the Focus Figure-of-merit metadata to select the transmitted image, instead of selecting on file size
# Only works for lenses with autofocus (PiCam v3)
# Only useful for lenses with autofocus (PiCam v3)
# --use_focus_fom

python3 tx_picamera2_gps.py \
Expand Down
20 changes: 15 additions & 5 deletions tx/WenetPiCamera2.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,21 @@ def init_camera(self):
if self.af_offset != 0:
tuning = Picamera2.load_tuning_file("imx708.json")
map = Picamera2.find_tuning_algo(tuning, "rpi.af")["map"]
#print(map)
offset_hw = self.af_offset * (map[3]-map[1])/(map[2]-map[0])
for i in range(1, len(map), 2):
map[i] += offset_hw
#print(Picamera2.find_tuning_algo(tuning, "rpi.af")["map"])
self.debug_message(f"Default Focus Mapping: {map}")

if self.af_offset == -99:
# Custom map for testing the full extents of the lens range.
map[0] = 0.0
map[1] = 0.0
map[2] = 15.0
map[3] = 1024.0
else:
# Otherwise, apply an offset
offset_hw = self.af_offset * (map[3]-map[1])/(map[2]-map[0])
for i in range(1, len(map), 2):
map[i] += offset_hw

self.debug_message(f"Modified Focus Mapping: {Picamera2.find_tuning_algo(tuning, 'rpi.af')['map']}")

self.cam = Picamera2(0, tuning=tuning)

Expand Down

0 comments on commit 012dc01

Please sign in to comment.