Use Case Tutorial:

Pattern Matching with Polarized DoLP Image in MVTec HALCON

With tutorial and sample source code

Many machine vision users utilize third party GigE Vision software for their wide selection of image processing functions. With most polarization cameras on the market, users would have to import raw data into a software package such as MVTec HALCON and develop their own polarization processing algorithm before the data can be used with the available image processing libraries. With LUCID’s polarization cameras which have on-camera polarization processing, the data is pre-processed on the camera and users can import the data directly into any GigE Vision software and immediately work with the available image processing functions. This helps reduce development and integration time for the user.

In applications such as parts matching, it is important to capture a clear outline of the object in order for the matching algorithm to be effective. However phenomenons such as glare could make the object shape more difficult to distinguish. The DoLP data from a polarization camera can capture a clear outline of the edges and corners and is less susceptible to glare. The following example demonstrates how to configure the camera in MVTec HALCON to perform pattern matching on reflective, metal objects.

Requirements:

  • Triton (TRI050S-P/Q) or Phoenix (PHX050S-P/Q) 5.0 MP Polarization Camera
  • Triton 5.0 MP Polarized Firmware Version: 1.32.0.0 or higher or
  • Phoenix 5.0 MP Polarized Firmware Version: 1.40.0.0 or higher
  • MVTec HALCON – Win 32/64-bit Version: 13.0.1.1 or higher

Pattern Matching with Polarized DoLP Image in MVTec HALCON

Step 1. Connect LUCID’s polarization camera to MVTec HALCON

Please refer to our getting started guide on connecting to the software. Proceed to Step 2 once the camera is connected to MVTec HALCON.

Step 2. Enable DoLP pixel mapping to Mono8

In order to import DoLP data into HALCON, the DoLP data has to be mapped to a supported pixel format such as Mono8 so it can be imported by HALCON. By default, the mapping of the polarized data is not enabled. To enable this, select ImageFormatControl and set PixelFormatMappingEnable from 0 to 1.

After the mapping is enabled, click “Snap” under the “Connection” tab. The camera should send a DoLP image as a Mono8 image to HALCON. The same can be done for a color polarization camera using a Bayer8 image.

Step 3. 2D Matching using HALCON

With the polarized data mapped and imported in HALCON, users can start applying standard image processing functions to the image. The images below provides an example of using planar deformable matching to match objects in the DoLP image. The benefit of this type of matching is that objects with perspective deformation can also be matched.

Conclusion

With on-camera polarization processing, the user can reduce software development and hardware integration time when working with LUCID’s polarization cameras. Users can start testing their applications right away using third party software libraries such as MVTec HALCON.

The code below provides an example of using planar deformable matching to match objects in the DoLP image (jpeg image)

<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.2" halcon_version="19.05.0.0">
<procedure name="main">
<interface/>
<body>
<c></c>
<c> * Initialization</c>
<l> dev_update_off ()</l>
<l>list_image_files ('', 'default', [], ImageFiles)</l>
<l>read_image (ImageModel, ImageFiles[0])</l>
<l>get_image_size (ImageModel, Width, Height)</l>
<l>dev_open_window (0, 0, Width/2, Height/2, 'black', WindowHandle)</l>
<l>dev_set_color ('green')</l>
<l>set_display_font (WindowHandle, 16, 'mono', 'true', 'false')</l>
<c></c>
<c>* Generation of a planar deformable model</c>
<l>gen_rectangle1 (ROI, 256.015, 795.572, 935.935, 2123.41)</l>
<l>reduce_domain (ImageModel, ROI, ImageTemplate)</l>
<l>median_image (ImageTemplate, ImageTemplateMedian, 'circle', 5, 'mirrored')</l>
<l>create_planar_uncalib_deformable_model (ImageTemplateMedian, 'auto', [], [], 'auto', 1, [], 'auto', 1, [], 'auto', 'none', 'use_polarity', [3,30], 'auto', [], [], ModelID)</l>
<l>get_deformable_model_contours (ModelContours, ModelID, 1)</l>
<c></c>
<l>for Index := 0 to |ImageFiles|-1 by 1</l>
<l>    read_image (Image, ImageFiles[Index])</l>
<c>    </c>
<c>    * Image Preprocessing</c>
<l>    rgb1_to_gray (Image, GrayImage)</l>
<l>    median_image (GrayImage, ImageMedian, 'circle', 5, 'mirrored')</l>
<c></c>
<c>    * Matching</c>
<l>    find_planar_uncalib_deformable_model (ImageMedian, ModelID, 0, rad(360), 1, 1, 1, 1, 0.1, 0, 0, 0, 0.9, [], [], HomMat2D, Score)</l>
<c>    </c>
<c>    * Visualization - Display found models.</c>
<l>    dev_display (ImageMedian)</l>
<l>    for Index1 := 0 to |Score| - 1 by 1</l>
<l>        tuple_select_range (HomMat2D, Index1 * 9, ((Index1 + 1) * 9) - 1, HomMat2DSelected)</l>
<l>        projective_trans_contour_xld (ModelContours, ContoursProjTrans, HomMat2DSelected)</l>
<l>        dev_display (ContoursProjTrans)</l>
<l>    endfor</l>
<l>    dev_disp_text (|Score| + ' Matches found', 'window', 'top', 'left', 'black', [], [])</l>
<l>    stop()</l>
<l>endfor</l>
<c></c>
<c>* Clearing</c>
<l>clear_deformable_model (ModelID)</l>
</body>
<docu id="main">
<parameters/>
</docu>
</procedure>
</hdevelop>