Run Halcon (C# version) in Visual Studio

Run Halcon in Visual Studio (C# configures Halcon environment)

Foreword:
This article records the various pitfalls of running Halcon in VS, and builds a VS halcon project from scratch, posting for experience.

1. Create a VS project and a Halcon project
VS select Windows Forms application (.NET Framework), as shown in the figure below:
insert image description here
Just write the most common image reading code in Halcon, as follows:
insert image description here
Then convert the halcon file into a C# file. Click the file in the upper left corner, select the export language, and configure it as follows:
insert image description here

2. Configuration environment
In the Halcon folder, find the bin folder, as follows:
insert image description here
Select dotnet35 to open, and then copy halcondotnet.dll, as follows:
insert image description here
In the VS project, select "WindowsFormsApp1—bin—Debug" in turn to open the configuration of the VS project folder. Copy halcondotnet.dll to this directory. As follows:
insert image description here
There are three pitfalls here:
1. The file starting with windows in the above picture is only available after running VS, don’t worry;
2. Some tutorials will also copy halcon.dll here, but halcon The .dll is not compiled by C#, so the C# environment cannot open the file, and an error will be reported, just don’t quote the file;
3. The license file should also be copied there, but in the folder of our local halcon, the license folder There is only one txt file in it, which cannot be used normally. You need to download the pass file and put it in this folder (the pass file is updated every month, pay attention to the date of download).
3. Prepare VS
First, click Reference→Add Reference to add halcondotnet.dll. As follows:
insert image description here
Note : Do not reference halcon.dll, otherwise an error will be reported: Please ensure that this file is accessible and is a valid assembly or COM component. As follows:
insert image description here
After that, click the toolbox, right-click "All Windows Forms", and click Select Items.
insert image description here
Then click "Browse" to reference halcondotnet.dll:
insert image description here
Then find HWidowControl
insert image description here
and place it in the form, and then place a button, as follows:
insert image description here
4. Run
Open the cs file generated by halcon, find the action function, and copy it (currently, this function is useful in the entire file)
insert image description here
button in the Form1 window, enter the code interface,
insert image description here
paste the code in the action function here, and Replace the image path with your own image. As follows:
insert image description here
Then start and run, but after clicking the button, there is still no picture. This is because we did not add the display code, as follows:
insert image description here
After adding, start and run again, click the button, and the picture is displayed.

over

Guess you like

Origin blog.csdn.net/Deng7326/article/details/128885301