def load_calibration_data_from_env(self): """Load calibration parameters from environment variable.""" self.calibration_params = ENV.load(self.env_var_name) if self.calibration_params is None: raise ValueError("ENV load failed.")
def env_var_converter(self, widget): """Convert environment variable contents to dictionary.""" common_app_var_names = [ 'blur', 'morph', 'iteration', 'H_HI', 'H_LO', 'S_HI', 'S_LO', 'V_HI', 'V_LO'] calibration_names = [ 'total_rotation_angle', 'easy_calibration', 'invert_hue_selection', 'image_bot_origin_location', 'coord_scale', 'camera_offset_y', 'camera_offset_x', 'calibration_object_separation', 'calibration_along_axis', 'camera_z', 'center_pixel_location_x', 'center_pixel_location_y'] options_app_var_names = [ 'WEED_DETECTOR_' + n for n in common_app_var_names] calibration_app_var_names = [ 'CAMERA_CALIBRATION_' + n for n in ( common_app_var_names + calibration_names)] if 'calibration' in widget: app_var_names = calibration_app_var_names input_template = copy.deepcopy(self.cdefaults) else: app_var_names = options_app_var_names input_template = copy.deepcopy(self.defaults) invert_hue_selection = False try: if input_template['invert_hue_selection']: invert_hue_selection = True except KeyError: pass for name in app_var_names: loaded_value = ENV.load(name) if loaded_value is not None: if 'H_LO' in name: input_template['H'][0] = loaded_value elif 'H_HI' in name: input_template['H'][1] = loaded_value elif 'S_LO' in name: input_template['S'][0] = loaded_value elif 'S_HI' in name: input_template['S'][1] = loaded_value elif 'V_LO' in name: input_template['V'][0] = loaded_value elif 'V_HI' in name: input_template['V'][1] = loaded_value elif 'iteration' in name: input_template['iterations'] = loaded_value elif 'calibration_along_axis' in name: input_template['calibration_circles_xaxis'] = bool( 'x' in loaded_value.lower()) elif 'calibration_object_separation' in name: input_template[ 'calibration_circle_separation'] = loaded_value elif 'image_bot_origin_location' in name: if 'bottom_left' in loaded_value.lower(): input_template['image_bot_origin_location'] = [0, 1] if 'top_left' in loaded_value.lower(): input_template['image_bot_origin_location'] = [0, 0] if 'bottom_right' in loaded_value.lower(): input_template['image_bot_origin_location'] = [1, 1] if 'top_right' in loaded_value.lower(): input_template['image_bot_origin_location'] = [1, 0] elif 'camera_offset_x' in name: input_template[ 'camera_offset_coordinates'][0] = loaded_value elif 'camera_offset_y' in name: input_template[ 'camera_offset_coordinates'][1] = loaded_value elif 'center_pixel_location_x' in name: try: input_template['center_pixel_location'][0] except KeyError: input_template['center_pixel_location'] = [0, 0] input_template['center_pixel_location'][0] = loaded_value elif 'center_pixel_location_y' in name: try: input_template['center_pixel_location'][0] except KeyError: input_template['center_pixel_location'] = [0, 0] input_template['center_pixel_location'][1] = loaded_value elif 'invert_hue_selection' in name: invert_hue_selection = bool('true' in loaded_value.lower()) elif 'easy_calibration' in name: input_template['easy_calibration'] = bool( 'true' in loaded_value.lower()) else: for cname in calibration_names + common_app_var_names: if cname in name: input_template[cname] = loaded_value if invert_hue_selection: if input_template['H'][0] < input_template['H'][1]: input_template['H'] = input_template['H'][::-1] else: if input_template['H'][0] > input_template['H'][1]: input_template['H'] = input_template['H'][::-1] return input_template
"""Download an image from the Web App and use it to calibrate the camera. download the image corresponding to the ID provided and run calibration """ import os import sys sys.path.insert(1, os.path.join(sys.path[0], '..')) from plant_detection.PlantDetection import PlantDetection from plant_detection import ENV from plant_detection.CeleryPy import log if __name__ == "__main__": IMAGE_ID = ENV.load('CAMERA_CALIBRATION_selected_image', get_json=False) if IMAGE_ID is None: log('No image selected.', message_type='error', title='historical-camera-calibration') sys.exit(0) PD = PlantDetection(coordinates=True, app=True, app_image_id=IMAGE_ID) PD.calibrate()
#!/usr/bin/env python """Plant Detection Image Capture. For Plant Detection. """ import sys import os from time import time, sleep from subprocess import call import cv2 from plant_detection import ENV from plant_detection.Log import log CAMERA = (ENV.load('camera', get_json=False) or 'USB').upper() class Capture(object): """Capture image for Plant Detection.""" def __init__(self, directory=None): """Set initial attributes.""" self.image = None self.ret = None self.camera_port = None self.image_captured = False self.silent = False self.directory = directory def camera_check(self): """Check for camera at ports 0 and 1.""" if not os.path.exists('/dev/video' + str(self.camera_port)):
"""Download an image from the Web App and detect coordinates. download the image corresponding to the ID provided and run plant detection and coordinate conversion """ import os import sys sys.path.insert(1, os.path.join(sys.path[0], '..')) from plant_detection.PlantDetection import PlantDetection from plant_detection import ENV from plant_detection.CeleryPy import log if __name__ == "__main__": IMAGE_ID = ENV.load('PLANT_DETECTION_selected_image', get_json=False) if IMAGE_ID is None: log('No image selected.', message_type='error', title='historical-plant-detection') sys.exit(0) PD = PlantDetection(coordinates=True, app=True, app_image_id=IMAGE_ID) PD.detect_plants()
#!/usr/bin/env python """Plant Detection Image Capture. For Plant Detection. """ import sys import os from time import time, sleep from subprocess import call import cv2 from plant_detection import ENV from plant_detection.Log import log CAMERA = ENV.load('camera', get_json=False) if CAMERA is None: CAMERA = 'USB' # default camera else: if 'RPI' in CAMERA: CAMERA = 'RPI' # Raspberry Pi Camera else: CAMERA = 'USB' class Capture(object): """Capture image for Plant Detection.""" def __init__(self): """Set initial attributes.""" self.image = None self.ret = None self.camera_port = None self.image_captured = False