Halcon-based XLD (sub-pixel contour) to Region (pixel region) algorithm code (does not change the original XLD line structure, supports simultaneous conversion of multiple contours, and retains the original connectivity and contour sorting)

Keywords: Halcon; XLD (sub-pixel outline); Region (pixel area); line detection; edge detection; machine vision detection; image processing

In machine vision inspection, line detection requirements for cracks and scratches are often involved (as shown in Figure 1). When Halcon is used for programming detection, commonly used line detection (such as lines_gauss operator) or edge detection methods (such as edges_color_sub_pix Operator), the final output result (as shown in Figure 2) is mostly XLD (sub-pixel contour) type, but most of the operators of Blob analysis and other methods target the variable type mostly as Region. However, the built-in XLD to Region operator (such as gen_region_contour_xld operator) in Halcon can only convert it into a closed area (as shown in Figure 3) and a closed boundary area (as shown in Figure 4), which changes the structure of the original line and cannot Normal follow-up morphological analysis.

Therefore, in response to the common needs in the actual combat of this project, I sorted out my own conversion function XLD_to_Region (Lines, OutRegion), which can be converted into Region type without changing the original XLD line structure, and supports simultaneous conversion of multiple contours. And retain the original connectivity and contour sorting, the effect is shown in Figure 5. Through joint programming, the code can be embedded in projects such as C++, C# and Python, and due to the morphological method mainly used in the algorithm, the operation efficiency is high, and it can be applied to machine vision online inspection projects.
insert image description hereFigure 1 The original image of the crack
insert image description hereFigure 2 The XLD contour line of the crack extracted by Gaussian line detection
insert image description hereFigure 3 The effect of the XLD to Region operator built in Halcon (closed area)

insert image description hereFigure 4. The XLD to Region operator effect in Halcon (closed border area)
insert image description hereFigure 5. The self-built XLD_to_Region operator conversion effect

The source code of the program can be downloaded from the network disk link on the WeChat public account [Dongguan Scientific Research].
insert image description here

Guess you like

Origin blog.csdn.net/u014751362/article/details/131864687