diff --git a/README.md b/README.md index 18fb5e1..51d17c4 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ from the camera can be used. configured settings for each frame. - [CaptureSavePLY](https://github.com/zivid/zivid-halcon-samples/tree/master//source/Camera/Basic/CaptureSavePLY.hdev) - Capture a 3D color point cloud from the camera and save it to a PLY file format. + - [CaptureWithSettingsFromJSON](https://github.com/zivid/zivid-halcon-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromJSON.hdev) - Capture a 3D color point cloud from the camera and use it + to generate a HALCON ObjectModel3D which is then visualized. - [ConnectToSerialNumberCamera](https://github.com/zivid/zivid-halcon-samples/tree/master//source/Camera/Basic/ConnectToSerialNumberCamera.hdev) - Connect to a specific Zivid 3D camera based on its serial number. - **Advanced** diff --git a/source/Camera/Basic/CaptureWithSettingsFromJSON.hdev b/source/Camera/Basic/CaptureWithSettingsFromJSON.hdev new file mode 100644 index 0000000..866b53e --- /dev/null +++ b/source/Camera/Basic/CaptureWithSettingsFromJSON.hdev @@ -0,0 +1,73 @@ + + + + + + * + * Capture a 3D color point cloud from the camera and use it to generate a HALCON ObjectModel3D which is then visualized. + * + * Please note that you first need to install Zivid Software and correctly set the environment variables. After this, you can access the camera with the HALCON + * GenICamTL interface. + * + + * Preparing graphics windows + dev_close_window () + WinWidth := 960 + WinHeight := 800 + dev_open_window (0, 0, WinWidth, WinHeight, 'blue', Window3D) + dev_open_window (0, WinWidth, WinWidth, WinHeight, 'black', Window2D) + + *Getting first available Zivid device + info_framegrabber ('GenICamTL','device', Information, Devices) + import './../../Procedures' + get_first_available_zivid_device (Devices, Device) + + * Connecting to Zivid camera + open_framegrabber ('GenICamTL',1, 1, 0, 0, 0, 0, 'progressive', -1, 'default', -1, 'false', 'default', Device, 0, 0, AcqHandle) + + * Loading settings from file + get_zivid_sample_data_dir(ZividDataDir) + get_framegrabber_param (AcqHandle, 'DeviceModelName', DeviceModelName) + get_zivid_model_folder_name (DeviceModelName, DeviceModelFolder) + read_dict (ZividDataDir + '/SettingsJson/' + DeviceModelFolder + '/Settings01.json', [], [], JsonSettings) + read_zivid_json_params (AcqHandle, JsonSettings) + + * Configuring acquisition + set_framegrabber_param (AcqHandle, 'create_objectmodel3d', 'enable') + set_framegrabber_param (AcqHandle, 'add_objectmodel3d_overlay_attrib', 'enable') + set_framegrabber_param (AcqHandle, 'grab_timeout', -1) + + * Capturing frame + grab_data (Image, Region, Contours, AcqHandle, ObjectModel3D) + + * Extracting the following images: X, Y, Z, SNR, and RGB + select_obj (Image, X, 1) + select_obj (Image, Y, 2) + select_obj (Image, Z, 3) + select_obj (Image, Confidence, 4) + select_obj (Image, RGBA, 5) + + * Displaying 2D color image + dev_set_window (Window2D) + dev_display (RGBA) + + * Displaying 3D color point cloud, press the button to continue + Instructions[0] := 'Rotate: Left button' + Instructions[1] := 'Zoom: Shift + left button' + Instructions[2] := 'Move: Ctrl + left button' + visualize_object_model_3d (Window3D, ObjectModel3D, [], [], ['red_channel_attrib','green_channel_attrib','blue_channel_attrib'], ['&overlay_red','&overlay_green','&overlay_blue'], [], [], [Instructions], PoseOut) + + * Disconnecting from Zivid Camera + close_framegrabber (AcqHandle) + + * Closing graphics windows + dev_set_window (Window2D) + dev_close_window () + dev_set_window (Window3D) + dev_close_window () + + + + + + diff --git a/source/Procedures/read_zivid_json_params.hdvp b/source/Procedures/read_zivid_json_params.hdvp index 676d659..3988d61 100644 --- a/source/Procedures/read_zivid_json_params.hdvp +++ b/source/Procedures/read_zivid_json_params.hdvp @@ -34,6 +34,18 @@ set_framegrabber_param (AcqHandle, 'AddAcquisition', 1) endfor + * Engine + get_dict_tuple (Settings, 'Experimental', Experimental) + get_dict_tuple (Experimental, 'Engine', Engine) + set_framegrabber_param (AcqHandle, 'ExperimentalEngine', Engine) + + * Sampling + get_dict_tuple (Settings, 'Sampling', Sampling) + get_dict_tuple (Sampling, 'Color', SamplingColor) + get_dict_tuple (Sampling, 'Pixel', SamplingPixel) + set_framegrabber_param (AcqHandle, 'SamplingColor', SamplingColor) + set_framegrabber_param (AcqHandle, 'SamplingPixel', SamplingPixel) + * RegionOfInterest get_dict_tuple (Settings, 'RegionOfInterest', RegionOfInterest) @@ -99,6 +111,12 @@ set_framegrabber_param (AcqHandle, 'ProcessingFiltersNoiseRemovalEnabled', Enabled) get_dict_tuple (Removal, 'Threshold', Threshold) set_framegrabber_param (AcqHandle, 'ProcessingFiltersNoiseRemovalThreshold', Threshold) + get_dict_tuple (Noise, 'Suppression', Suppression) + get_dict_tuple (Suppression, 'Enabled', Enabled) + set_framegrabber_param (AcqHandle, 'ProcessingFiltersNoiseSuppressionEnabled', Enabled) + get_dict_tuple (Noise, 'Repair', Repair) + get_dict_tuple (Repair, 'Enabled', Enabled) + set_framegrabber_param (AcqHandle, 'ProcessingFiltersNoiseRepairEnabled', Enabled) * Outlier Filter get_dict_tuple (Filters, 'Outlier', Outlier) diff --git a/source/SampleUtils/yaml_settings_to_json.py b/source/SampleUtils/yaml_settings_to_json.py index 33fb3f1..76625f2 100644 --- a/source/SampleUtils/yaml_settings_to_json.py +++ b/source/SampleUtils/yaml_settings_to_json.py @@ -22,6 +22,22 @@ def _args() -> argparse.Namespace: return parser.parse_args() +def _convert_to_halcon_format(yaml_object: dict) -> None: + """Recursively search through a dictionary and convert necessary values to Halcon-supported format. + + Args: + yaml_object: YAML loaded as a dictionary + + """ + for key, value in yaml_object.items(): + if value == "yes": + yaml_object[key] = 1 + elif value == "no": + yaml_object[key] = 0 + elif isinstance(value, dict): + _convert_to_halcon_format(value) + + def _main() -> None: input_directory = _args().directory if not input_directory.is_dir(): @@ -31,8 +47,9 @@ def _main() -> None: for x in list(_args().directory.glob("*.yml")): output_file = output_directory / f"{x.stem}.json" with open(x, "r", encoding="utf-8") as yaml_in, open(output_file, "w", encoding="utf-8") as json_out: - yaml_object = yaml.safe_load(yaml_in) - json.dump(yaml_object, json_out, indent=2) + yaml_dict = yaml.safe_load(yaml_in) + _convert_to_halcon_format(yaml_dict) + json.dump(yaml_dict, json_out, indent=4) if __name__ == "__main__":