<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.0" halcon_version="10.0.2" cs="707214738">
<procedure name="main">
<interface/>
<body>
<c>* This example illustrates how to </c>
<c>* 1. Acquire data from the Gocator (16-bit RGB or gray image)</c>
<c>* 2. Decompose the returned image into three separate image for height map, intensity and stamps. </c>
<c>* 3. Extract some stamp values from the stamp image.</c>
<c></c>
<c>* Connect to the Gocator device. This code is auto generated by the Image Acquisition dialog box. User can manually override the directory path by editing the line below.</c>
<c>* Set image type to 'rgb' if the format is 16-bit RGB. 'gray' if the format is 16-bit mono</c>
<l>open_framegrabber ('GenICamTL', 0, 0, 0, 0, 0, 0, 'progressive', 16, 'rgb', -1, 'false', 'default', '192.168.1.10 producer:C:\\SOFTWARE_Go2_Tools\\GenTL\\x86\\Go2GenTL.cti interface:0:XX::GenTL vendor:LMI model:Gocator', 0, -1, AcqHandle)</l>
<c></c>
<l>grab_image_start (AcqHandle, -1)   </l>
<c></c>
<l>while (true)         </l>
<l>    try</l>
<l>        grab_image_async (Image, AcqHandle, -1)</l>
<l>    catch(Exception)</l>
<l>        continue</l>
<l>    endtry</l>
<c>    </c>
<l>    Go2GenTL_ParseData (Image, HeightMap, Intensity, frameCount, timestamp, encoderPosition, encoderIndex, inputs, xOffset, xResolution, yOffset, yResolution, zOffset, zResolution, width, height, hasIntensity)</l>
<l>    dev_display(HeightMap)    </l>
<c>    </c>
<c>    * Image Acquisition Routines Start ****</c>
<c>    </c>
<c>    * Create window of the image width and height</c>
<l>    dev_close_window ()</l>
<l>    dev_open_window (0, 0, width, height, 'black', WindowID)</l>
<c>    </c>
<c>    * Calculate the X, Y and Z coordinate at the center of gravity</c>
<c>    </c>
<c>    * Create a region that only contains positive height. Logical value of 32767 represents 0 height (refer to manual for more details)</c>
<l>    threshold(HeightMap, PositiveRegionRoi, 32768, 65535)</l>
<c>    </c>
<c>    * Create area of center of gravity</c>
<l>    area_center_gray(PositiveRegionRoi, HeightMap, area, centerRow, centerColumn)</l>
<c>    </c>
<c>    * Convert center to values and display on height map</c>
<l>    Go2GenTL_CoordinateXYZ (HeightMap, centerRow, centerColumn, xOffset, yOffset, zOffset, xResolution, yResolution, zResolution, coordinateXYZ)</l>
<l>    scale_image(HeightMap, HeightMapMM, zResolution, zOffset)    </l>
<l>    dev_clear_window()</l>
<l>    dev_display(HeightMapMM)</l>
<l>    disp_message(WindowID, 'Center of gravity', 'image', 0, 0, 'black', 'true')</l>
<l>    disp_message(WindowID, 'COG (x, y, z): (' + coordinateXYZ[0] + ',' + coordinateXYZ[1] + ',' + coordinateXYZ[2] + ')', 'image', centerRow, centerColumn, 'red', 'true')</l>
<l>    disp_continue_message(WindowID, 'black', 'true')</l>
<l>    stop()</l>
<c>    </c>
<c>    * Calculate intensity image. If intensity is not enabled, this image is all 0</c>
<l>    if (hasIntensity)        </l>
<l>        dev_clear_window()</l>
<c>        * Values in the intensity are scaled up by 256</c>
<l>        scale_image(Intensity, IntensityScaled, 1.0/256, 0)</l>
<l>        dev_display(IntensityScaled)</l>
<l>        disp_message(WindowID, 'Intensity', 'image', 0, 0, 'black', 'true')    </l>
<l>        disp_continue_message(WindowID, 'black', 'true')</l>
<l>        stop()</l>
<l>    endif</l>
<c>    </c>
<c>    * Image Acquisition Routines End ****</c>
<l>endwhile</l>
<l as_id="image_acquisition" as_name="Image Acquisition 01" as_grp="[4,1]" as_ord="1">close_framegrabber (AcqHandle)</l>
<c></c>
<c></c>
<c></c>
</body>
<docu id="main">
<parameters/>
</docu>
</procedure>
<procedure name="Go2GenTLStamp">
<interface>
<io>
<par name="Stamps"/>
</io>
<ic>
<par name="Index"/>
</ic>
<oc>
<par name="Value"/>
</oc>
</interface>
<body>
<c>  * Check if we are on a 64-bit machine</c>
<l> test_value := 0xFFFFFFFF</l>
<l> if (test_value &gt; 0)</l>
<l>     is64bit := 1</l>
<l> else</l>
<l>     is64bit := 0</l>
<l> endif </l>
<c></c>
<l> get_grayval(Stamps, 0, (Index * 4), tempvalue0)</l>
<l> get_grayval(Stamps, 0, (Index * 4) + 1, tempvalue1)</l>
<l> get_grayval(Stamps, 0, (Index * 4) + 2, tempvalue2)</l>
<l> get_grayval(Stamps, 0, (Index * 4) + 3, tempvalue3)</l>
<c> </c>
<c> * The actual stamp from the Gocator is 64-bit. tempvalue0 is the most significant 16-bit (i.e. the top bit is the sign bit)</c>
<c> * The code below assumes we only need the bottom 32-bit information. User need to update this conversion function if they want to </c>
<c> * return 64-bit value.</c>
<c> </c>
<l> if (is64bit = 1)</l>
<l>     tuple_lsh(tempvalue0, 48, tempvalue0)</l>
<l>     tuple_lsh(tempvalue1, 32, tempvalue1)</l>
<l>     tuple_lsh(tempvalue2, 16,tempvalue2)</l>
<l>     tuple_lsh(tempvalue3, 0,tempvalue3)</l>
<l>     Value := tempvalue0 + tempvalue1 + tempvalue2 + tempvalue3</l>
<l> else</l>
<l>     tuple_lsh(tempvalue2, 16,tempvalue2)</l>
<l>     tuple_lsh(tempvalue3, 0,tempvalue3)</l>
<l>     Value := tempvalue2 + tempvalue3</l>
<l> endif</l>
<l>return ()</l>
</body>
<docu id="Go2GenTLStamp">
<parameters>
<parameter id="Index"/>
<parameter id="Stamps"/>
<parameter id="Value"/>
</parameters>
</docu>
</procedure>
<procedure name="Go2GenTL_ResampleMode">
<interface>
<ic>
<par name="AcqHandle"/>
</ic>
<oc>
<par name="ResampleMode"/>
</oc>
</interface>
<body>
<l>get_framegrabber_param(AcqHandle, 'ResampleMode', ResampleMode)</l>
<l>return ()</l>
</body>
<docu id="Go2GenTL_ResampleMode">
<parameters>
<parameter id="AcqHandle"/>
<parameter id="ResampleMode"/>
</parameters>
</docu>
</procedure>
<procedure name="Go2GenTL_Encoder">
<interface>
<ic>
<par name="AcqHandle"/>
</ic>
<oc>
<par name="EncoderValue"/>
</oc>
</interface>
<body>
<l>get_framegrabber_param(AcqHandle, 'EncoderValue0', EncoderValue0)</l>
<l>get_framegrabber_param(AcqHandle, 'EncoderValue1', EncoderValue1)</l>
<l>EncoderValue[0] := EncoderValue0</l>
<l>EncoderValue[1] := EncoderValue1</l>
<c></c>
<l>return ()</l>
</body>
<docu id="Go2GenTL_Encoder">
<parameters>
<parameter id="AcqHandle"/>
<parameter id="EncoderValue"/>
</parameters>
</docu>
</procedure>
<procedure name="Go2GenTL_SetConfigFileName">
<interface>
<ic>
<par name="AcqHandle"/>
<par name="ConfigFileName"/>
</ic>
</interface>
<body>
<l>set_framegrabber_param(AcqHandle, 'ConfigFile', ConfigFileName)</l>
<l>return ()</l>
</body>
<docu id="Go2GenTL_SetConfigFileName">
<parameters>
<parameter id="AcqHandle"/>
<parameter id="ConfigFileName">
<default_type>string</default_type>
<sem_type>string</sem_type>
<type_list>
<item>string</item>
</type_list>
</parameter>
</parameters>
</docu>
</procedure>
<procedure name="Go2GenTL_ConfigFileName">
<interface>
<ic>
<par name="AcqHandle"/>
</ic>
<oc>
<par name="ConfigFile"/>
</oc>
</interface>
<body>
<l>get_framegrabber_param(AcqHandle, 'ConfigFile', ConfigFile)</l>
<l>return ()</l>
</body>
<docu id="Go2GenTL_ConfigFileName">
<parameters>
<parameter id="AcqHandle"/>
<parameter id="ConfigFile"/>
</parameters>
</docu>
</procedure>
<procedure name="Go2GenTL_ImageSize">
<interface>
<ic>
<par name="AcqHandle"/>
</ic>
<oc>
<par name="Width"/>
<par name="Height"/>
</oc>
</interface>
<body>
<l>get_framegrabber_param(AcqHandle, 'image_width', Width)</l>
<l>get_framegrabber_param(AcqHandle, 'image_height', Height)</l>
<l>return ()</l>
</body>
<docu id="Go2GenTL_ImageSize">
<parameters>
<parameter id="AcqHandle"/>
<parameter id="Height"/>
<parameter id="Width"/>
</parameters>
</docu>
</procedure>
<procedure name="Go2GenTL_ParseData">
<interface>
<io>
<par name="Image"/>
</io>
<oo>
<par name="HeightMap"/>
<par name="Intensity"/>
</oo>
<oc>
<par name="FrameCount"/>
<par name="Timestamp"/>
<par name="EncoderPosition"/>
<par name="EncoderIndex"/>
<par name="Inputs"/>
<par name="xOffset"/>
<par name="xResolution"/>
<par name="yOffset"/>
<par name="yResolution"/>
<par name="zOffset"/>
<par name="zResolution"/>
<par name="Width"/>
<par name="Length"/>
<par name="HasIntensity"/>
</oc>
</interface>
<body>
<l>count_channels(Image, channelCount)</l>
<c></c>
<l>if (channelCount = 1)</l>
<c>    </c>
<l>    get_image_size(Image, monoImageWidth, monoImageHeight)</l>
<l>    crop_rectangle1(Image, Stamps, monoImageHeight - 1, 0, monoImageHeight-1, monoImageWidth)</l>
<c>    </c>
<l>    Go2GenTLStamp (Stamps, 1, FrameCount)</l>
<l>    Go2GenTLStamp (Stamps, 2, Timestamp)</l>
<l>    Go2GenTLStamp (Stamps, 3, EncoderPosition)</l>
<l>    Go2GenTLStamp (Stamps, 4, EncoderIndex)</l>
<l>    Go2GenTLStamp (Stamps, 5, Inputs)</l>
<l>    Go2GenTLStamp (Stamps, 6, xOffset)</l>
<l>    Go2GenTLStamp (Stamps, 7, xResolution)</l>
<l>    Go2GenTLStamp (Stamps, 8, yOffset)</l>
<l>    Go2GenTLStamp (Stamps, 9, yResolution)</l>
<l>    Go2GenTLStamp (Stamps, 10, zOffset)</l>
<l>    Go2GenTLStamp (Stamps, 11, zResolution)</l>
<l>    Go2GenTLStamp (Stamps, 12, Width)</l>
<l>    Go2GenTLStamp (Stamps, 13, Length)</l>
<l>    Go2GenTLStamp (Stamps, 14, HasIntensity)</l>
<c>    </c>
<l>    crop_rectangle1(Image, HeightMap, 0, 0, Length - 1, Width)</l>
<l>    if (HasIntensity = 1)</l>
<l>        IntensityPosition := (monoImageHeight - 1)/2</l>
<l>        crop_rectangle1(Image, Intensity, IntensityPosition, 0, IntensityPosition + Length - 1, Width)    </l>
<l>    else</l>
<l>        gen_image_const(Intensity, 'byte', Width, Length)</l>
<l>    endif</l>
<c>    </c>
<l>elseif (channelCount = 3)</l>
<c>    </c>
<l>    decompose3(Image, HeightMap, Intensity, Stamps)</l>
<c></c>
<l>    Go2GenTLStamp (Stamps, 1, FrameCount)</l>
<l>    Go2GenTLStamp (Stamps, 2, Timestamp)</l>
<l>    Go2GenTLStamp (Stamps, 3, EncoderPosition)</l>
<l>    Go2GenTLStamp (Stamps, 4, EncoderIndex)</l>
<l>    Go2GenTLStamp (Stamps, 5, Inputs)</l>
<l>    Go2GenTLStamp (Stamps, 6, xOffset)</l>
<l>    Go2GenTLStamp (Stamps, 7, xResolution)</l>
<l>    Go2GenTLStamp (Stamps, 8, yOffset)</l>
<l>    Go2GenTLStamp (Stamps, 9, yResolution)</l>
<l>    Go2GenTLStamp (Stamps, 10, zOffset)</l>
<l>    Go2GenTLStamp (Stamps, 11, zResolution)</l>
<l>    Go2GenTLStamp (Stamps, 12, Width)</l>
<l>    Go2GenTLStamp (Stamps, 13, Length)</l>
<l>    Go2GenTLStamp (Stamps, 14, HasIntensity)</l>
<l>endif</l>
<c></c>
<l>return ()</l>
</body>
<docu id="Go2GenTL_ParseData">
<parameters>
<parameter id="EncoderIndex"/>
<parameter id="EncoderPosition"/>
<parameter id="FrameCount"/>
<parameter id="HasIntensity"/>
<parameter id="HeightMap"/>
<parameter id="Image"/>
<parameter id="Inputs"/>
<parameter id="Intensity"/>
<parameter id="Length"/>
<parameter id="Timestamp"/>
<parameter id="Width"/>
<parameter id="xOffset"/>
<parameter id="xResolution"/>
<parameter id="yOffset"/>
<parameter id="yResolution"/>
<parameter id="zOffset"/>
<parameter id="zResolution"/>
</parameters>
</docu>
</procedure>
<procedure name="Go2GenTL_CoordinateXYZ">
<interface>
<io>
<par name="heightMap"/>
</io>
<ic>
<par name="rowIdx"/>
<par name="columnIdx"/>
<par name="xOffset"/>
<par name="yOffset"/>
<par name="zOffset"/>
<par name="xResolution"/>
<par name="yResolution"/>
<par name="zResolution"/>
</ic>
<oc>
<par name="coordinateXYZ"/>
</oc>
</interface>
<body>
<c>* real-world coordinate = value * resolution + offset. The result will be in um, so divide </c>
<c>* 1000 to get mm</c>
<c></c>
<l>coordinateXYZ[0] := (columnIdx * xResolution + xOffset) / 1000.0</l>
<c>* Ignore yOffset to get distance relative to the beginning of the part. </c>
<c>* Include yOffset to get absolute distance</c>
<l>coordinateXYZ[1] := (rowIdx * yResolution + yOffset) / 1000.0</l>
<l>*coordinateXYZ[1] := (rowIdx * yResolution) / 1000.0</l>
<l>tuple_round(columnIdx, columnInteger)</l>
<l>tuple_round(rowIdx, rowInteger)</l>
<l>get_grayval(heightMap, rowInteger, columnInteger, heightValue)</l>
<l>coordinateXYZ[2] := (heightValue * zResolution + zOffset) / 1000.0</l>
<l>return ()</l>
</body>
<docu id="Go2GenTL_CoordinateXYZ">
<parameters>
<parameter id="columnIdx"/>
<parameter id="coordinateXYZ"/>
<parameter id="heightMap"/>
<parameter id="rowIdx"/>
<parameter id="xOffset"/>
<parameter id="xResolution"/>
<parameter id="yOffset"/>
<parameter id="yResolution"/>
<parameter id="zOffset"/>
<parameter id="zResolution"/>
</parameters>
</docu>
</procedure>
<procedure name="Go2GenTL_Transformation">
<interface>
<ic>
<par name="AcqHandle"/>
</ic>
<oc>
<par name="XOffset"/>
<par name="ZOffset"/>
<par name="Angle"/>
<par name="Orientation"/>
<par name="ClearanceDistance"/>
</oc>
</interface>
<body>
<l>get_framegrabber_param (AcqHandle, 'TransformationXOffsetReg', XOffset)</l>
<l>get_framegrabber_param (AcqHandle, 'TransformationZOffsetReg', ZOffset)</l>
<l>get_framegrabber_param (AcqHandle, 'TransformationAngleReg', Angle)</l>
<l>get_framegrabber_param (AcqHandle, 'TransformationOrientationReg', Orientation)</l>
<l>get_framegrabber_param (AcqHandle, 'ClearanceDistanceReg', ClearanceDistance)</l>
<l>return ()</l>
</body>
<docu id="Go2GenTL_Transformation">
<parameters>
<parameter id="AcqHandle"/>
<parameter id="Angle"/>
<parameter id="ClearanceDistance"/>
<parameter id="Orientation"/>
<parameter id="XOffset"/>
<parameter id="ZOffset"/>
</parameters>
</docu>
</procedure>
</hdevelop>
