def test_params_import(self): """ Tests importing params from json Settings -------- sample_config: dict{string: dict{string: value}} config for setting params for SimpleBlobDetector Returns ------- list[bool] whether each configuration matches the expected value """ sample_config = { "filterByArea": { "enable": True, "minArea": 200 }, "filterByColor": { "enable": False, "blobColor": 100 } } params = import_params(sample_config) for category, settings in sample_config.items(): with self.subTest(i=category): enabled = sample_config[category]['enable'] for param, value in settings.items(): if param == 'enable': self.assertEqual(getattr(params, category), value, msg=f"Expected attribute '{category}' to have value '{value}', got '{getattr(params, category)}' instead") elif enabled: self.assertEqual(getattr(params, param), value, msg=f"Expected attribute '{param}' to have value '{value}', got '{getattr(params, param)}' instead") ## Ensure does not modify original parameter config_original = { "filterByArea": { "enable": True, "minArea": 200 }, "filterByColor": { "enable": False, "blobColor": 100 } } config_parameter = deepcopy(config_original) import_params(config_parameter) self.assertDictEqual(config_original, config_parameter)
def __init__(self, vision_communication, flight_communication, camera): warnings.filterwarnings("ignore") ## self.vision_communication = vision_communication self.flight_communication = flight_communication self.camera = camera.__iter__() ## if os.path.isdir("vision"): prefix = "vision" elif os.path.isdir("integration_tests"): prefix = "../vision" else: prefix = "" # config_filename = os.path.join(prefix, "obstacle", "config.json") with open(config_filename, "r") as config_file: config = json.load(config_file) self.obstacle_finder = ObstacleFinder(params=import_params(config)) self.obstacle_tracker = ObstacleTracker() self.text_detector = TextDetector() self.module_location = ModuleLocation() self.vision_flags = Queue()
def setup(self): """ Setup obstacle detector """ prefix = '' if os.path.isdir("times") else '..' config_filename = os.path.join(prefix, '..', 'obstacle', 'config.json') with open(config_filename, 'r') as config_file: config = json.load(config_file) self.blob_finder = ObstacleFinder(params=import_params(config))
def setup(self) -> None: """ Setup obstacle detector via json file. Returns ------- None """ config_filename = os.path.join("vision", "obstacle", "config.json") with open(config_filename, "r") as config_file: config = json.load(config_file) self.obstacle_finder = ObstacleFinder(params=import_params(config)) self.obstacle_tracker = ObstacleTracker()
def setup(self): """ Configure blob detector and initialize images. """ ## Generate images self.PARAMETERS = {} self.PARAMETERS.update(common.blank_dimensions()) base_color, base_depth = common.blank_dimensions(self.DEFAULT_DIMS) # for radius in [25, 50, 100, 250]: color_image, depth_image = np.copy(base_color), np.copy(base_depth) cv2.circle(color_image, (640, 360), radius, (255, 255, 255), thickness=-1) cv2.circle(depth_image, (640, 360), radius, (255), thickness=-1) self.PARAMETERS.update({f'radius={radius}': (color_image, depth_image)}) # One to each corner for n_obj in range(4): color_image, depth_image = np.copy(base_color), np.copy(base_depth) for location in [(320, 180), (320, 540), (960, 180), (960, 540)][:n_obj]: cv2.circle(color_image, location, self.DEFAULT_RADIUS, (255, 255, 255), thickness=-1) cv2.circle(depth_image, location, self.DEFAULT_RADIUS, (255), thickness=-1) self.PARAMETERS.update({f'n_obj={n_obj}': (color_image, depth_image)}) # On default noise specturm for title, (color_image, depth_image) in common.noise().items(): cv2.circle(color_image, (640, 360), self.DEFAULT_RADIUS, (255, 255, 255), thickness=-1) cv2.circle(depth_image, (640, 360), self.DEFAULT_RADIUS, (255), thickness=-1) self.PARAMETERS.update({f'{title} single': (color_image, depth_image)}) ## Read current params & setup obstacle detector prefix = '' if os.path.isdir("times") else '..' config_filename = os.path.join(prefix, '..', 'obstacle', 'config.json') with open(config_filename, 'r') as config_file: config = json.load(config_file) self.blob_finder = ObstacleFinder(params=import_params(config))
def __init__(self, vision_communication, flight_communication, camera): ## self.vision_communication = vision_communication self.flight_communication = flight_communication self.camera = camera.__iter__() ## prefix = 'vision' if os.path.isdir("vision") else '' # config_filename = os.path.join(prefix, 'obstacle', 'config.json') with open(config_filename, 'r') as config_file: config = json.load(config_file) self.obstacle_finder = ObstacleFinder(params=import_params(config)) self.module_location = ModuleLocation()
bottom_left_near ] # , top_left_far, top_right_far, bottom_right_far, bottom_left_far] # create Rectangle and add to list of bounding boxes bbox = BoundingBox(vertices, ObjectType.AVOID) bounding_boxes.append(bbox) return bounding_boxes if __name__ == '__main__': from vision.common.box_plotter import plot_box prefix = 'vision' if os.path.isdir("vision") else '' img_folder = os.path.join(prefix, 'vision_images', 'obstacle') config_filename = os.path.join(prefix, 'obstacle', 'config.json') with open(config_filename, 'r') as config_file: config = json.load(config_file) for img in os.listdir(img_folder): if img[-4:] not in ['.png', '.jpg']: continue image = cv2.imread(os.path.join(img_folder, os.fsdecode(img))) obstacle_finder = ObstacleFinder(params=import_params(config)) bboxes = obstacle_finder.find(image, None) plot_box(bboxes, image)