Halcon From Basics to Mastery-02- Develop HALCON-based applications

HALCON applications are prototyped through the HDevelop application. There are three main forms of HDevelop development.

  • Start from Scratch:

Manually convert HDevelop code into a general programming language through scripts. For example, as mentioned in the previous section, in fact, each operator may be different, and it is necessary to determine which programming language is supported based on the HALCON Operator Reference.

  • Export HDevelop Code:

Conversion is automated via HDevelop.

  • Export Library Project:

Partially compile through the library + corresponding CMake file.


HDevelop:

1 Simple example of detecting PCB board:

[Case] ​​Let’s look at an example:

This is an example of using HALCON to detect a circuit. The connection operator of HALCON is called to directly determine the connectivity of objects in the image.

[If I enlarge this picture]

[Case] ​​The part with the red arrow is actually the part where the HALCON software correctly recognizes that the circuit PCB has an error and is disconnected.

The code for the above implementation of HALCON is extremely simple, as follows: 

read_image (Image, 'pcb')
threshold (Image, Region, 0, 122)
connection (Region, ConnectedRegions)
count_obj (ConnectedRegions, Number)

2 HDevelop project integration methods:

2.1 Output the algorithm as a Procedure: [Set in HDevelop]

Right-click to create a processing module:

 Select [First In, Last Out]

 Save project

2.2 Take VS2019 as an example to configure HALCON project settings: [Setting in VS2019]

[Create a HALCON VS project, project name: vs_count_regions_HALCON] 

[Note, set to X64] 

[Setting VC++] include directory

 $(HALCONROOT)\include;$(HALCONROOT)\include\halconcpp;

Set the Lib directory of Linker: 

$(HALCONROOT)\lib\$(HALCONARCH);

Set additional dependent libraries:

 halconcpp.lib;hdevenginecpp.lib;

2.3 Merge the HALCON project just generated into VS2019 [HDevelop]

[Choose to export]

The following files will be generated:

2.4 Add the HALCON file just generated: vs_count_regions_HALCON VS2019 project

 In VS2019, add the file: vs_count_regions.cpp to the project

 And in the file, enter the following code:

#include <iostream>
#include "HalconCpp.h"
#include "hdev_count_regions/source/hdev_count_regions.h"
int main()
{
	HalconCpp::HImage Image("pcb");
	hdev_count_regions::SetResourcePath("hdev_count_regions/res_hdev_count_regions");
	HalconCpp::HTuple Number{};
	hdev_count_regions::count_regions(Image, &Number);
	std::cout << "Number of Regions: " << Number.L() << '\n';
}

 Then, add the production file of HALCON just now to VS2019 as follows:

2.4 Run HALCON’s small project library [HDevelop] in VS2019

In VS 2019, join and open the file vs_count_regions.cpp: Generate Scheme

Then, run this scenario,

【summary】

In this way, an application of HALCON to determine the connection was successfully called through VS2019.


reference:

HALCONQuickGuide version 23.05 resources-CSDN library

Guess you like

Origin blog.csdn.net/yellow_hill/article/details/133581214