Add AF offset option

rfm98w_packettx
Mark Jessop 2024-11-02 20:35:52 +10:30
rodzic 769240e6c8
commit f4f7523d99
3 zmienionych plików z 29 dodań i 3 usunięć

Wyświetl plik

@ -92,11 +92,14 @@ sleep 10
# Additional configuration lines you may wish to add or remove before the $CALLSIGN line may include: # Additional configuration lines you may wish to add or remove before the $CALLSIGN line may include:
# Flip the image vertically and horizontally (e.g. if the camera is mounted upside down) # Flip the image vertically and horizontally (e.g. if the camera is mounted upside down)
# --vflip --hflip \ # --vflip --hflip \
#
# Add a logo overlay in the bottom right of the image. This must be a transparent PNG file. # Add a logo overlay in the bottom right of the image. This must be a transparent PNG file.
# --logo yourlogo.png \ # --logo yourlogo.png \
#
# Set a fixed focus position on a PiCam v3 (NOTE: The Picamv3 focus drifts with temperature - beware!!!) # Set a fixed focus position on a PiCam v3 (NOTE: The Picamv3 focus drifts with temperature - beware!!!)
# 0.0 = Infinity # 0.0 = Infinity
# --lensposition 0.0 \ # --lensposition 0.0 \
#
# Set a user-defined AutoFocus Window Area, for use wiith PiCam v3 in Autofocus Mode # Set a user-defined AutoFocus Window Area, for use wiith PiCam v3 in Autofocus Mode
# Must be provided as x,y,w,h , with all values between 0-1.0, where: # Must be provided as x,y,w,h , with all values between 0-1.0, where:
# x: Starting X position of rectangle within frame, as fraction of frame width # x: Starting X position of rectangle within frame, as fraction of frame width
@ -104,7 +107,11 @@ sleep 10
# w: Width of rectangle, as fraction of frame width # w: Width of rectangle, as fraction of frame width
# h: Height of rectangle, as fraction of frame height # h: Height of rectangle, as fraction of frame height
# e.g: # e.g:
# --afwindow 0.25,0.25,0.5,0.5 # --afwindow 0.25,0.25,0.5,0.5 \
#
# Set a fixed lens offset for the PiCam v3, in dioptres. May help with autofocus in cold temperatures.
# e.g. to offset by 1 dioptre:
# --afoffset -1.0 \
python3 tx_picamera2_gps.py \ python3 tx_picamera2_gps.py \
--rfm98w $SPIDEVICE \ --rfm98w $SPIDEVICE \

Wyświetl plik

@ -54,6 +54,7 @@ class WenetPiCamera2(object):
whitebalance = 'auto', whitebalance = 'auto',
lens_position = -1, lens_position = -1,
af_window = None, af_window = None,
af_offset = 0,
temp_filename_prefix = 'picam_temp', temp_filename_prefix = 'picam_temp',
debug_ptr = None, debug_ptr = None,
init_retries = 10 init_retries = 10
@ -85,6 +86,7 @@ class WenetPiCamera2(object):
w: Width of rectangle, as fraction of frame width w: Width of rectangle, as fraction of frame width
h: Height of rectangle, as fraction of frame height h: Height of rectangle, as fraction of frame height
If not provided, the default windowing (approx centre third of width/height) will be used. If not provided, the default windowing (approx centre third of width/height) will be used.
af_offset: Offset the lens by a fixed dioptre. May help with autofocus during flights.
temp_filename_prefix: prefix used for temporary files. temp_filename_prefix: prefix used for temporary files.
debug_ptr: 'pointer' to a function which can handle debug messages. debug_ptr: 'pointer' to a function which can handle debug messages.
@ -103,6 +105,7 @@ class WenetPiCamera2(object):
self.vertical_flip = vertical_flip self.vertical_flip = vertical_flip
self.lens_position = lens_position self.lens_position = lens_position
self.af_window = af_window self.af_window = af_window
self.af_offset = af_offset
self.af_window_rectangle = None # Calculated during init self.af_window_rectangle = None # Calculated during init
self.autofocus_mode = False self.autofocus_mode = False
@ -139,7 +142,20 @@ class WenetPiCamera2(object):
except: except:
pass pass
self.cam = Picamera2() # Apply a lens offset if we have been provided one.
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.cam = Picamera2(0, tuning=tuning)
else:
self.cam = Picamera2()
self.camera_properties = self.cam.camera_properties self.camera_properties = self.cam.camera_properties
@ -328,6 +344,7 @@ class WenetPiCamera2(object):
# Copy best image to target filename. # Copy best image to target filename.
self.debug_message("Copying image to storage with filename %s" % filename) self.debug_message("Copying image to storage with filename %s" % filename)
os.system("cp %s %s" % (largest_pic, filename)) os.system("cp %s %s" % (largest_pic, filename))
# Clean up temporary images. # Clean up temporary images.
os.system("rm %s_*.jpg" % self.temp_filename_prefix) os.system("rm %s_*.jpg" % self.temp_filename_prefix)

Wyświetl plik

@ -34,6 +34,7 @@ parser.add_argument("--resize", type=float, default=0.5, help="Resize raw image
parser.add_argument("--whitebalance", type=str, default='daylight', help="White Balance setting: Auto, Daylight, Cloudy, Incandescent, Tungesten, Fluorescent, Indoor") parser.add_argument("--whitebalance", type=str, default='daylight', help="White Balance setting: Auto, Daylight, Cloudy, Incandescent, Tungesten, Fluorescent, Indoor")
parser.add_argument("--lensposition", type=float, default=-1.0, help="For PiCam v3, set the lens position. Default: -1 = Continuous Autofocus") parser.add_argument("--lensposition", type=float, default=-1.0, help="For PiCam v3, set the lens position. Default: -1 = Continuous Autofocus")
parser.add_argument("--afwindow", type=str, default=None, help="For PiCam v3 Autofocus mode, set the AutoFocus window, x,y,w,h , in fractions of frame size. (Default: None = default)") parser.add_argument("--afwindow", type=str, default=None, help="For PiCam v3 Autofocus mode, set the AutoFocus window, x,y,w,h , in fractions of frame size. (Default: None = default)")
parser.add_argument("--afoffset", type=float, default=0.0, help="For PiCam v3 Autofocus mode, offset the lens by this many dioptres (Default: 0 = No offset)")
parser.add_argument("-v", "--verbose", action='store_true', default=False, help="Show additional debug info.") parser.add_argument("-v", "--verbose", action='store_true', default=False, help="Show additional debug info.")
args = parser.parse_args() args = parser.parse_args()
@ -211,7 +212,8 @@ picam = WenetPiCamera2.WenetPiCamera2(
horizontal_flip=args.hflip, horizontal_flip=args.hflip,
whitebalance=args.whitebalance, whitebalance=args.whitebalance,
lens_position=args.lensposition, lens_position=args.lensposition,
af_window=args.afwindow af_window=args.afwindow,
af_offset=args.afoffset
) )
# .. and start it capturing continuously. # .. and start it capturing continuously.
picam.run(destination_directory="./tx_images/", picam.run(destination_directory="./tx_images/",