2020import os
2121import pathlib as plib
2222import shutil
23+ import warnings
2324import tqdm
2425from picamerax import PiCamera
2526from fractions import Fraction
@@ -161,7 +162,26 @@ def collect_dataset(config):
161162 camera .close ()
162163
163164 # -- now set up camera with desired settings
164- camera = PiCamera (sensor_mode = 0 , resolution = tuple (res ), framerate = config .capture .framerate )
165+ max_increase = (
166+ config .capture .fact_increase * config .max_tries
167+ if config .max_tries > 0
168+ else 1
169+ )
170+ max_exposure = min (20 , config .capture .exposure * max_increase )
171+ if config .capture .framerate is None :
172+ framerate = 1 / max_exposure
173+ warnings .warn (
174+ f"Framerate is not given. Setting it to 1 / max_exposure = { framerate } "
175+ )
176+ elif config .capture .framerate > 1 / max_exposure :
177+ warnings .warn (
178+ f"Framerate should be less or equal 1 / max_exposure = { 1 / max_exposure } . Resetting framerate"
179+ )
180+ framerate = 1 / max_exposure
181+ else :
182+ framerate = config .capture .framerate
183+
184+ camera = PiCamera (sensor_mode = 0 , resolution = tuple (res ), framerate = framerate )
165185
166186 # Set ISO to the desired value
167187 camera .resolution = tuple (res )
@@ -175,8 +195,8 @@ def collect_dataset(config):
175195 init_shutter_speed = int (config .capture .exposure * 1e6 )
176196 else :
177197 init_shutter_speed = camera .exposure_speed
178- camera .shutter_speed = init_shutter_speed
179198 camera .exposure_mode = "off"
199+ camera .shutter_speed = init_shutter_speed
180200
181201 # AWB
182202 if config .capture .awb_gains :
@@ -362,8 +382,10 @@ def capture_screen(
362382 fact_decrease = config .capture .fact_decrease
363383 n_tries = 0
364384
365- camera .shutter_speed = int (init_shutter_speed )
366- time .sleep (config .capture .config_pause )
385+ if MAX_TRIES > 0 :
386+ # shutter speed is constant for MAX_TRIES == 0
387+ camera .shutter_speed = int (init_shutter_speed )
388+ time .sleep (config .capture .config_pause )
367389 current_shutter_speed = camera .shutter_speed
368390
369391 current_screen_brightness = init_brightness
0 commit comments