diff --git a/config/vision/labels/test_absence.pbtxt b/config/vision/labels/test_absence.pbtxt new file mode 100644 index 0000000..12fa2ca --- /dev/null +++ b/config/vision/labels/test_absence.pbtxt @@ -0,0 +1,10 @@ +item { + id: 1 + name: 'ok' + color: '0x55AA55' +} +item { + id: 2 + name: 'ko' + color: '0xff0000' +} diff --git a/config/vision/labels/test_presence.pbtxt b/config/vision/labels/test_presence.pbtxt new file mode 100644 index 0000000..12fa2ca --- /dev/null +++ b/config/vision/labels/test_presence.pbtxt @@ -0,0 +1,10 @@ +item { + id: 1 + name: 'ok' + color: '0x55AA55' +} +item { + id: 2 + name: 'ko' + color: '0xff0000' +} diff --git a/config/vision/recipes/test_absence.ini b/config/vision/recipes/test_absence.ini new file mode 100644 index 0000000..efd1cf8 --- /dev/null +++ b/config/vision/recipes/test_absence.ini @@ -0,0 +1,20 @@ +# O-RING PRESENCE DETECTOR +# FOR FERRARI 000952054 + +[general] +name: test Assemza +instruction: CONTROLLARE PRESENZA PUNTO VERDE +neural_network: none +type: smart_camera +camera_type: hikrobot_sc +num_cameras: 1 +rotations=0 +solution_name=test_absent + +[markers] + +[zones] +p1: 620,630 600,600 ok + +[labels] + diff --git a/config/vision/recipes/test_absent.scsln b/config/vision/recipes/test_absent.scsln new file mode 100644 index 0000000..956f124 Binary files /dev/null and b/config/vision/recipes/test_absent.scsln differ diff --git a/config/vision/recipes/test_presence.ini b/config/vision/recipes/test_presence.ini new file mode 100644 index 0000000..f1aacad --- /dev/null +++ b/config/vision/recipes/test_presence.ini @@ -0,0 +1,20 @@ +# O-RING PRESENCE DETECTOR +# FOR FERRARI 000952054 + +[general] +name: Test presenza +instruction: CONTROLLARE PRESENZA PUNTO VERDE +neural_network: none +type: smart_camera +camera_type: hikrobot_sc +num_cameras: 1 +rotations=0 +solution_name=test_presence + +[markers] + +[zones] +p1: 620,630 600,600 ok + +[labels] + diff --git a/config/vision/recipes/test_presence.scsln b/config/vision/recipes/test_presence.scsln new file mode 100644 index 0000000..15cab5c Binary files /dev/null and b/config/vision/recipes/test_presence.scsln differ diff --git a/src/components/hikrobot_sc/hikrobot_sc.py b/src/components/hikrobot_sc/hikrobot_sc.py index c92580d..522858f 100644 --- a/src/components/hikrobot_sc/hikrobot_sc.py +++ b/src/components/hikrobot_sc/hikrobot_sc.py @@ -23,7 +23,7 @@ class HikrobotSmartCamera(Component): self.ok_frames = [] self.ok_results =[] - def config_changed(self, vision_recipe=None): + def config_changed(self): self.connected = False global MV_VS_OK device_info_list = MV_VS_DEVICE_INFO_LIST() @@ -85,32 +85,8 @@ class HikrobotSmartCamera(Component): return -2 # Set the camera recipe - # Load recipe from vision/recipes directory - if vision_recipe is not None: - # Use the vision_recipe parameter to load the recipe - from configparser import ConfigParser - from pathlib import Path - - recipes_dir = Path("./config/vision/recipes") - recipe_path = recipes_dir / f"{vision_recipe}.ini" - - if recipe_path.exists(): - config = ConfigParser(inline_comment_prefixes="#") - config.read(recipe_path) - if "general" in config and "solution_name" in config["general"]: - solutionName = config["general"]["solution_name"] - self.log.info(f"Loading solution: {solutionName} from {recipe_path}") - mv_lib.MV_VS_SetStringValue(pHandle, "SrcOperateSolutionName", solutionName) - mv_lib.MV_VS_SetCommandValue(pHandle, "CommandProjectLoad") - time.sleep(5) - else: - self.log.error(f"No solution_name found in {recipe_path}") - else: - self.log.error(f"Recipe file not found: {recipe_path}") - elif self.config.get("general", {}).get("solution_name", None) is not None: - # Fallback to the old method if vision_recipe is not provided - solutionName = self.config["general"]["solution_name"] - self.log.info(f"Using fallback solution: {solutionName}") + if self.config.vision_config.get("solution_name",None) is not None: + solutionName = self.config.vision_config["solution_name"] mv_lib.MV_VS_SetStringValue(pHandle, "SrcOperateSolutionName", solutionName) mv_lib.MV_VS_SetCommandValue(pHandle, "CommandProjectLoad") time.sleep(5) @@ -122,14 +98,14 @@ class HikrobotSmartCamera(Component): self.connected = True @Component.reconfig_on_error - def _get(self, vision_recipe=None): + def _get(self): if not self.connected: - self.config_changed(vision_recipe=vision_recipe) + self.config_changed() if not self.connected: return concat_frame = None concat_results = [] - rot = self.config["general"]["rotations"].split(",") + rot = self.config.vision_config["rotations"].split(",") for cam_idx in range(self.num_cameras): cam = self.cam_list[cam_idx] self.log.info(f"GET FRAME CAMERA # {cam_idx}") @@ -160,7 +136,6 @@ class HikrobotSmartCamera(Component): frame = cv2.rotate(frame, cv2.ROTATE_180) else: self.connected = False - return if concat_frame is None: concat_frame = copy.deepcopy(frame) else: @@ -172,10 +147,10 @@ class HikrobotSmartCamera(Component): super()._get([concat_frame, self.ok_results]) - def resume(self, vision_recipe=None): + def resume(self): self.log.info(f"RESUMING") if not self.connected: - self.config_changed(vision_recipe=vision_recipe) + self.config_changed() if self.connected: # init OK result memory self.ok_frames = [None for n in range(self.num_cameras)] diff --git a/src/main.py b/src/main.py index 9d0155a..21a662d 100644 --- a/src/main.py +++ b/src/main.py @@ -180,7 +180,7 @@ try: self.components["vision"].set_sources({"hikrobot_sc": self.components["hikrobot_sc"].out}) # Connect the recipe_changed_signal from Vision to HikrobotSmartCamera self.components["vision"].recipe_changed_signal.connect( - lambda recipe_name: self.components["hikrobot_sc"].config_changed(vision_recipe=recipe_name) + lambda recipe_name: self.components["hikrobot_sc"].config_changed() ) # connect tecna to screwdriver