def test_wrong_background_size(self): pipeline_parameters = { "camera_name": "simulation", "image_background": "white_background" } simulated_camera = CameraSimulation(CameraConfig("simulation")) image = simulated_camera.get_image() x_axis, y_axis = simulated_camera.get_x_y_axis() background_provider = MockBackgroundManager() # Invalid background size. background_provider.save_background("white_background", numpy.zeros(shape=(100, 100)), append_timestamp=False) parameters = PipelineConfig("test_pipeline", pipeline_parameters).get_configuration() image_background_array = background_provider.get_background("white_background") with self.assertRaisesRegex(RuntimeError, "Invalid background_image size "): process_image(image=image, timestamp=time.time(), x_axis=x_axis, y_axis=y_axis, parameters=parameters, image_background_array=image_background_array)
def test_image_background(self): pipeline_parameters = { "camera_name": "simulation", "image_background": "white_background" } simulated_camera = CameraSimulation(CameraConfig("simulation")) image = simulated_camera.get_image() x_axis, y_axis = simulated_camera.get_x_y_axis() background_provider = MockBackgroundManager() x_size, y_size = simulated_camera.get_geometry() background_provider.save_background("white_background", numpy.zeros(shape=(y_size, x_size)), append_timestamp=False) pipeline_config = PipelineConfig("test_pipeline", pipeline_parameters) parameters = pipeline_config.get_configuration() image_background_array = background_provider.get_background(parameters.get("image_background")) result = process_image(image=image, timestamp=time.time(), x_axis=x_axis, y_axis=y_axis, parameters=parameters, image_background_array=image_background_array) self.assertTrue(numpy.array_equal(result["image"], image), "A zero background should not change the image.") max_value_in_image = result["max_value"] pipeline_parameters = { "camera_name": "simulation", "image_background": "max_background", "image_threshold": 0 } max_background = numpy.zeros(shape=(y_size, x_size), dtype="uint16") max_background.fill(max_value_in_image) background_provider.save_background("max_background", max_background, append_timestamp=False) pipeline_config = PipelineConfig("test_pipeline", pipeline_parameters) parameters = pipeline_config.get_configuration() image_background_array = background_provider.get_background(parameters.get("image_background")) expected_image = numpy.zeros(shape=(y_size, x_size)) result = process_image(image=image, timestamp=time.time(), x_axis=x_axis, y_axis=y_axis, parameters=parameters, image_background_array=image_background_array) self.assertTrue(numpy.array_equal(result["image"], expected_image), "The image should be all zeros - negative numbers are not allowed.")
def test_pipeline_background_manager(self): manager = multiprocessing.Manager() stop_event = multiprocessing.Event() statistics = manager.Namespace() parameter_queue = multiprocessing.Queue() pipeline_config = PipelineConfig("test_pipeline", parameters={ "camera_name": "simulation", "image_background": "full_background", "image_background_enable": True, "image_threshold": 0 }) background_manager = MockBackgroundManager() with self.assertRaises(Exception): processing_pipeline(stop_event, statistics, parameter_queue, self.client, pipeline_config, 12000, background_manager) simulated_camera_shape = (960, 1280) background_array = numpy.zeros(shape=simulated_camera_shape) background_array.fill(99999) background_manager.save_background("full_background", background_array, append_timestamp=False) def send(): processing_pipeline(stop_event, statistics, parameter_queue, self.client, pipeline_config, 12000, background_manager) thread = Thread(target=send) thread.start() with source(host="127.0.0.1", port=12000, mode=SUB) as stream: data = stream.receive() self.assertIsNotNone(data, "Received None message.") self.assertTrue( numpy.array_equal(data.data.data["image"].value, numpy.zeros(shape=simulated_camera_shape))) stop_event.set() thread.join()