Skip to content

Commit

Permalink
Samples: Update Halcon samples
Browse files Browse the repository at this point in the history
This commit:

- Adds warmup sample
- fixes a bug when reading camera model
  • Loading branch information
chrisasc committed Apr 3, 2023
1 parent a3dff17 commit 0b2c312
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<c/>
<l>for Index := 1 to 5 by 1</l>
<c/>
<l> tuple_add (ScenePath, '/im', SceneFilename)</l>
<l> tuple_add (ScenePath, '/Im', SceneFilename)</l>
<l> tuple_add (SceneFilename, Index, SceneFilename)</l>
<l> tuple_add (SceneFilename, '.ply', SceneFilename) </l>
<l> read_object_model_3d (SceneFilename, 'm', ['xyz_map_width'], [1920], ObjectModel3DScene, Status)</l>
Expand Down
5 changes: 3 additions & 2 deletions source/Camera/Advanced/CaptureHDRLoop.hdev
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<c>* Connecting to Zivid camera</c>
<l>open_framegrabber ('GenICamTL', 1, 1, 0, 0, 0, 0, 'progressive', -1, 'default', -1, 'false', 'default', Device, 0, 0, AcqHandle)</l>
<l>get_framegrabber_param (AcqHandle, 'DeviceModelName', DeviceModelName)</l>
<l>tuple_substr (DeviceModelName, 0, 8, DeviceModelFolder)</l>
<l>get_zivid_model_folder_name (DeviceModelName, DeviceModelFolder)</l>
<c/>
<c>* Configuring 3D-settings</c>
<l>set_framegrabber_param (AcqHandle, 'create_objectmodel3d', 'enable')</l>
Expand All @@ -45,7 +45,8 @@
<l> set_framegrabber_param (AcqHandle, 'ResetAcquisitions', 1)</l>
<c/>
<c> * Configuring HDR settings for frames</c>
<l> set_settings (AcqHandle, ZividDataDir + '/SettingsJson/' + DeviceModelFolder +'/Settings0'+(Index+1)+'.json')</l>
<l> read_dict (ZividDataDir + '/SettingsJson/' + DeviceModelFolder + '/Settings01.json', [], [], JsonSettings)</l>
<l> read_zivid_json_params (AcqHandle, JsonSettings)</l>
<c/>
<c> * Capturing frame (HDR)</c>
<l> grab_data (Image, Region, Contours, AcqHandle, ObjectModel3D)</l>
Expand Down
67 changes: 67 additions & 0 deletions source/Camera/InfoUtilOther/Warmup.hdev
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.2" halcon_version="21.11.0.0">
<procedure name="main">
<interface/>
<body>
<c>*</c>
<c>* A basic warm-up method for a Zivid camera with specified time and capture cycle.</c>
<c>*</c>
<c/>
<c>* Preparing the graphics window</c>
<l>dev_close_window ()</l>
<l>WinWidth := 480</l>
<l>WinHeight := 400</l>
<l>dev_open_window (0, 0, WinWidth, WinHeight, 'black', Window3D)</l>
<c/>
<c>* Getting first available Zivid device</c>
<l>info_framegrabber ('GenICamTL','device', Information, Devices)</l>
<l>import './../../Procedures'</l>
<l>get_first_available_zivid_device (Devices, Device)</l>
<l>get_zivid_sample_data_dir(ZividDataDir)</l>
<c/>
<c>* Connecting to Zivid camera</c>
<l>open_framegrabber ('GenICamTL',1, 1, 0, 0, 0, 0, 'progressive', -1, 'default', -1, 'false', 'default', Device, 0, 0, AcqHandle)</l>
<c/>
<l>WarmupTimeMinutes := 10</l>
<l>CaptureCycle := 5</l>
<c/>
<c>* Reading JSON settings path</c>
<l>get_framegrabber_param (AcqHandle, 'DeviceModelName', DeviceModelName)</l>
<l>get_zivid_model_folder_name (DeviceModelName, DeviceModelFolder)</l>
<l>read_dict (ZividDataDir + '/SettingsJson/' + DeviceModelFolder + '/Settings01.json', [], [], JsonSettings)</l>
<l>read_zivid_json_params (AcqHandle, JsonSettings)</l>
<c/>
<l>dev_disp_text ('Starting warm up for: ' + WarmupTimeMinutes + ' minutes' , 'window', 60, 12, 'black', [], [])</l>
<c/>
<l>TimePast := 0</l>
<l>WarmupTime := WarmupTimeMinutes * 60</l>
<l>while(TimePast &lt; WarmupTime) </l>
<l> count_seconds(BeforeGrabData)</l>
<l> grab_data (Image, Region, Contours, AcqHandle, Data)</l>
<l> count_seconds(AfterGrabData)</l>
<c> </c>
<l> CaptureTime := AfterGrabData - BeforeGrabData</l>
<c> </c>
<l> if (CaptureTime &lt; CaptureCycle)</l>
<l> wait_seconds (CaptureCycle - CaptureTime) </l>
<l> else</l>
<l> dev_disp_text('Your capture time is longer than your desired capture cycle. Please increase the desired capture cycle.','window', 84, 12, 'black', [], [])</l>
<l> endif</l>
<c> </c>
<l> TimePast := TimePast + max([CaptureTime, CaptureCycle])</l>
<l> RemainingTime := WarmupTime - TimePast</l>
<l> RemainingTimeSeconds := max2 (0, int(RemainingTime) % 60)</l>
<l> RemainingTimeMinutes := int (RemainingTime - RemainingTimeSeconds) / 60</l>
<l> dev_disp_text('Remaining time: ' + RemainingTimeMinutes + ' minutes, ' + RemainingTimeSeconds + ' seconds' , 'window', 106, 12, 'black', [], [])</l>
<l>endwhile</l>
<c/>
<l>dev_disp_text('Warm up completed', 'window', 120, 12, 'black', [], [])</l>
<c/>
<c>* Closing graphics window </c>
<l>dev_close_window ()</l>
</body>
<docu id="main">
<parameters/>
</docu>
</procedure>
</hdevelop>
28 changes: 28 additions & 0 deletions source/Procedures/get_zivid_model_folder_name.hdvp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.2" halcon_version="21.11.0.0">
<procedure name="get_zivid_model_folder_name">
<interface>
<ic>
<par name="DeviceModelName" base_type="ctrl" dimension="0"/>
</ic>
<oc>
<par name="ZividFolder" base_type="ctrl" dimension="0"/>
</oc>
</interface>
<body>
<l>tuple_split(DeviceModelName, ' ', Substrings)</l>
<l>if (Substrings[1] == 'One')</l>
<l> ZividFolder := 'zividOne'</l>
<l>else</l>
<l> ZividFolder := 'zividTwo'</l>
<l>endif</l>
<l>return ()</l>
</body>
<docu id="get_zivid_model_folder_name">
<parameters>
<parameter id="DeviceModelName"/>
<parameter id="ZividFolder"/>
</parameters>
</docu>
</procedure>
</hdevelop>
110 changes: 110 additions & 0 deletions source/Procedures/read_zivid_json_params.hdvp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.2" halcon_version="21.11.0.0">
<procedure name="read_zivid_json_params">
<interface>
<ic>
<par name="AcqHandle" base_type="ctrl" dimension="0"/>
<par name="path" base_type="ctrl" dimension="0"/>
</ic>
</interface>
<body>
<l>get_dict_tuple (path, 'Settings', Settings)</l>
<l>get_dict_tuple (Settings,'Acquisitions', Acquisitions)</l>
<l>get_dict_param (Acquisitions, 'keys', [], AllKeys)</l>
<c/>
<c>* Single Capture or HDR</c>
<l>if (|AllKeys|==1)</l>
<l> set_framegrabber_param (AcqHandle, 'AcquisitionMode', 'SingleFrame')</l>
<l>elseif (|AllKeys| &gt; 1)</l>
<l> set_framegrabber_param (AcqHandle, 'AcquisitionMode', 'MultiAcquisitionFrame')</l>
<l>endif</l>
<c/>
<c>* Acquisition Settings</c>
<l>for Index := 0 to |AllKeys| -1 by 1</l>
<l> get_dict_tuple (Acquisitions, Index, AcquisitionIndex)</l>
<l> get_dict_tuple (AcquisitionIndex, 'Acquisition', Acquisition)</l>
<l> get_dict_tuple (Acquisition, 'ExposureTime', ExposureTime)</l>
<l> set_framegrabber_param(AcqHandle,'ExposureTime', ExposureTime)</l>
<l> get_dict_tuple (Acquisition, 'Aperture', Aperture)</l>
<l> set_framegrabber_param (AcqHandle, 'Aperture', Aperture)</l>
<l> get_dict_tuple(Acquisition, 'Brightness', Brightness) </l>
<l> set_framegrabber_param (AcqHandle, 'Brightness', Brightness)</l>
<l> get_dict_tuple(Acquisition, 'Gain', Gain) </l>
<l> set_framegrabber_param(AcqHandle, 'Gain', Gain)</l>
<l> set_framegrabber_param(AcqHandle, 'AddAcquisition',1)</l>
<l>endfor</l>
<c/>
<c>* Processing Settings</c>
<l>get_dict_tuple(Settings, 'Processing', Processing)</l>
<l>get_dict_tuple(Processing, 'Filters', Filters)</l>
<c/>
<c>* Noise Filter</c>
<l>get_dict_tuple(Filters, 'Noise', Noise)</l>
<l>get_dict_tuple(Noise, 'Removal', Removal)</l>
<l>get_dict_tuple(Removal,'Enabled',Enabled)</l>
<l>set_framegrabber_param(AcqHandle,'ProcessingFiltersNoiseRemovalEnabled', Enabled)</l>
<l>get_dict_tuple(Removal,'Threshold',Threshold)</l>
<l>set_framegrabber_param(AcqHandle,'ProcessingFiltersNoiseRemovalThreshold',Threshold)</l>
<c/>
<c>* Outlier Filter</c>
<l>get_dict_tuple(Filters, 'Outlier', Outlier)</l>
<l>get_dict_tuple(Outlier, 'Removal', Removal) </l>
<l>get_dict_tuple(Removal,'Enabled', Enabled)</l>
<l>set_framegrabber_param(AcqHandle,'ProcessingFiltersOutlierRemovalEnabled', Enabled)</l>
<l>get_dict_tuple(Removal,'Threshold', Threshold)</l>
<l>set_framegrabber_param (AcqHandle, 'ProcessingFiltersOutlierRemovalThreshold', Threshold)</l>
<c/>
<c>* Reflection Filter</c>
<l>get_dict_tuple(Filters, 'Reflection', Reflection)</l>
<l>get_dict_tuple(Reflection, 'Removal', Removal)</l>
<l>get_dict_tuple(Removal, 'Enabled', Enabled) </l>
<l>set_framegrabber_param (AcqHandle, 'ProcessingFiltersReflectionRemovalEnabled',Enabled)</l>
<l>get_dict_tuple(Removal,'Experimental', Experimental)</l>
<l>get_dict_tuple(Experimental,'Mode', Mode)</l>
<l>set_framegrabber_param(AcqHandle, 'ProcessingFiltersReflectionRemovalExperimentalMode',Mode)</l>
<c/>
<c>* Smoothing Filter</c>
<l>get_dict_tuple(Filters, 'Smoothing', Smoothing)</l>
<l>get_dict_tuple(Smoothing, 'Gaussian', Gaussian)</l>
<l>get_dict_tuple(Gaussian, 'Enabled', Enabled)</l>
<l>set_framegrabber_param(AcqHandle, 'ProcessingFiltersSmoothingGaussianEnabled',Enabled)</l>
<l>get_dict_tuple(Gaussian, 'Sigma', Sigma)</l>
<l>set_framegrabber_param(AcqHandle, 'ProcessingFiltersSmoothingGaussianSigma', Sigma)</l>
<c/>
<c>* ContrastDistortion Filter</c>
<l>get_dict_tuple(Filters, 'Experimental', Experimental)</l>
<l>get_dict_tuple(Experimental, 'ContrastDistortion', ContrastDistortion)</l>
<l>get_dict_tuple(ContrastDistortion, 'Correction', Correction)</l>
<l>get_dict_tuple(Correction, 'Enabled', Enabled)</l>
<l>get_dict_tuple(Correction, 'Strength', Strength)</l>
<l>set_framegrabber_param(AcqHandle, 'ProcessingFiltersExperimentalContrastDistortionCorrectionEnabled',Enabled)</l>
<l>set_framegrabber_param(AcqHandle, 'ProcessingFiltersExperimentalContrastDistortionCorrectionStrength',Strength)</l>
<l>get_dict_tuple(ContrastDistortion, 'Removal', Removal)</l>
<l>get_dict_tuple(Removal, 'Enabled', Enabled)</l>
<l>get_dict_tuple(Removal, 'Threshold', Threshold)</l>
<l>set_framegrabber_param(AcqHandle, 'ProcessingFiltersExperimentalContrastDistortionRemovalEnabled',Enabled)</l>
<l>set_framegrabber_param(AcqHandle, 'ProcessingFiltersExperimentalContrastDistortionRemovalThreshold',Threshold)</l>
<c/>
<c>* Color Settings</c>
<l>get_dict_tuple(Processing, 'Color', Color)</l>
<l>get_dict_tuple(Color, 'Balance', Balance)</l>
<l>get_dict_tuple(Balance, 'Blue', Blue)</l>
<l>get_dict_tuple(Balance, 'Green', Green)</l>
<l>get_dict_tuple(Balance, 'Red', Red)</l>
<l>set_framegrabber_param (AcqHandle,'ProcessingColorBalanceBlue', Blue)</l>
<l>set_framegrabber_param (AcqHandle,'ProcessingColorBalanceGreen', Green)</l>
<l>set_framegrabber_param (AcqHandle,'ProcessingColorBalanceRed', Red)</l>
<l>get_dict_tuple(Color, 'Experimental', Experimental)</l>
<l>get_dict_tuple(Experimental, 'Mode', Mode)</l>
<l>set_framegrabber_param(AcqHandle, 'ProcessingColorExperimentalMode', Mode)</l>
<c/>
<l>return ()</l>
</body>
<docu id="read_zivid_json_params">
<parameters>
<parameter id="AcqHandle"/>
<parameter id="path"/>
</parameters>
</docu>
</procedure>
</hdevelop>

0 comments on commit 0b2c312

Please sign in to comment.