diff --git a/start_tx.sh b/start_tx.sh index c3eb875..cd51143 100755 --- a/start_tx.sh +++ b/start_tx.sh @@ -92,11 +92,14 @@ sleep 10 # 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) # --vflip --hflip \ +# # Add a logo overlay in the bottom right of the image. This must be a transparent PNG file. # --logo yourlogo.png \ +# # Set a fixed focus position on a PiCam v3 (NOTE: The Picamv3 focus drifts with temperature - beware!!!) # 0.0 = Infinity # --lensposition 0.0 \ +# # 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: # 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 # h: Height of rectangle, as fraction of frame height # 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 \ --rfm98w $SPIDEVICE \ diff --git a/tx/WenetPiCamera2.py b/tx/WenetPiCamera2.py index 43cb5d6..c6deaa4 100644 --- a/tx/WenetPiCamera2.py +++ b/tx/WenetPiCamera2.py @@ -54,6 +54,7 @@ class WenetPiCamera2(object): whitebalance = 'auto', lens_position = -1, af_window = None, + af_offset = 0, temp_filename_prefix = 'picam_temp', debug_ptr = None, init_retries = 10 @@ -85,6 +86,7 @@ class WenetPiCamera2(object): w: Width of rectangle, as fraction of frame width h: Height of rectangle, as fraction of frame height 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. debug_ptr: 'pointer' to a function which can handle debug messages. @@ -103,6 +105,7 @@ class WenetPiCamera2(object): self.vertical_flip = vertical_flip self.lens_position = lens_position self.af_window = af_window + self.af_offset = af_offset self.af_window_rectangle = None # Calculated during init self.autofocus_mode = False @@ -139,7 +142,20 @@ class WenetPiCamera2(object): except: 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 @@ -328,6 +344,7 @@ class WenetPiCamera2(object): # Copy best image to target filename. self.debug_message("Copying image to storage with filename %s" % filename) os.system("cp %s %s" % (largest_pic, filename)) + # Clean up temporary images. os.system("rm %s_*.jpg" % self.temp_filename_prefix) diff --git a/tx/tx_picamera2_gps.py b/tx/tx_picamera2_gps.py index 7287a3a..bd10e4c 100644 --- a/tx/tx_picamera2_gps.py +++ b/tx/tx_picamera2_gps.py @@ -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("--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("--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.") args = parser.parse_args() @@ -211,7 +212,8 @@ picam = WenetPiCamera2.WenetPiCamera2( horizontal_flip=args.hflip, whitebalance=args.whitebalance, lens_position=args.lensposition, - af_window=args.afwindow + af_window=args.afwindow, + af_offset=args.afoffset ) # .. and start it capturing continuously. picam.run(destination_directory="./tx_images/",