Joint development of HALCON11 and VS2010

Source: Internet
Author: User
Tags lenovo

Just started to learn halcon, need to use Halcon and C + + joint development software, check the information on the Internet is Halcon10, I use the Halcon11 and VS2010 development environment, practice a bit found some problems, so the process of their own configuration to share.

First create a new Halcon project, here is a simple example of reading a picture.

Create a new Halcon program and enter the following code:

Read_image (image, ' c:/users/lenovo/desktop/test.jpg ') dev_open_window_fit_image (image, 0, 0,-1,-1, windowhandle) dev _clear_window () Dev_display (Image)

is actually to open a window and display a picture on the desktop

Then export the Halcon program as a C + + program

In Halcon, click on the menu bar, Export file.

After exporting, you can see a Halcon.cpp file on the desktop, the contents of this file are as follows:

The definition of function dev_open_window_fit_image is first declared and given:

void Dev_open_window_fit_image (Hobject ho_image, Htuple hv_row, Htuple Hv_column,
Htuple Hv_widthlimit, Htuple hv_heightlimit, Htuple *hv_windowhandle);

Then there is the definition of the function action, the code in the action corresponds to the code in the Halcon just now, simply speaking, the Halcon language is translated into C + +.

Main procedure void Action () {  //Local iconic variables   hobject  ho_image;  Local control Variables   htuple  hv_windowhandle;  Readimage (&ho_image, "c:/users/lenovo/desktop/test.jpg");  Dev_open_window_fit_image (ho_image, 0, 0,-1,-1, &hv_windowhandle);  if (Hdevwindowstack::isopen ())    ClearWindow (Hdevwindowstack::getactive ());  if (Hdevwindowstack::isopen ())    dispobj (Ho_image, hdevwindowstack::getactive ());}
Configure VS2010
In order to configure the VS2010 once and for all, let us in the future each new project will not have to re-add these messy configuration items, need to use the following techniques.
First create a new dialog-based MFC program, then click on the menu bar View-property manager, in the left side of the property manager, the default will be 32-bit debug and release properties. For a 64-bit system (now the computer is generally 64-bit system), you need to click on the menu bar generation, Configuration Manager, the platform options to x64, so that the generated files can be run under the 64-bit system.
Configure VS2010
In order to configure the VS2010 once and for all, let us in the future each new project will not have to re-add these messy configuration items, need to use the following techniques.
First create a new dialog-based MFC program, then click on the menu bar View-property manager , in the left side of the property manager, the default will be 32-bit debug and release properties. For a 64-bit system (now the computer is generally 64-bit system), you need to click on the menu bar generation, Configuration Manager , the platform options to x64, so that the generated files can be run under the 64-bit system.
After the change, the property manager will not change immediately, close the project and reopen it to see the new x64 properties.

The following is an example of the 64-bit debug attribute, which describes the configuration of Halcon 11.

Right-click on the User property and select Properties to go to the Properties page.

To the common properties in the VC + + directory to add the following directory, it is said halcon11 need to include halconcpp This folder is enough, Halcon10 is CPP. I use Halcon11, opened the installation directory after the discovery of two folders have, so the two directories are added.

The next step is the Library directory in VC + + directory .

The environment variable Halconroot in the directory is automatically written to the system environment variable when the Halcon is installed.

Continue, add the following two items to the additional include directory (and of course you can add $ (halconroot) \include\cpp) in the C + + directory, with no impact.

The most important one, configure the linker. Add $ (halconroot) \lib\$ (Halconarch) to the additional library directory of the regular item, and Halconarch is an environment variable.

Add Halconcpp.lib for the additional dependencies entered.

This completes the configuration.

Note that this is a way to configure the new project to inherit these configurations, which is convenient without reconfiguring.

MFC programs

Click View, Resource View, in the menu bar, and open the dialog box in Resource View.

In order to realize the function of displaying the picture, add a button in the dialog box and double click the button to enter the event response function, empty, wait for us to fill in.

void Chalconvcdlg::onbnclickedbutton1 () {//TODO: Add control notification handler code here}

First add the header file and namespace in the HalconVCDlg.h, because the declaration of the HALCON function will be added to this header file. The above header file and namespace are also added to the HalconVCDlg.cpp, as the Halcon function is called here.

#include "Halconcpp.h"

using namespace Halconcpp;

Open the Halcon.cpp that you just exported, in order to be able to call dev_open_window_fit_image this function in MFC, you need to put its declaration and definition into the MFC program. The declaration is copied to HalconVCDlg.h, note that it is placed outside the dialog class declaration and the definition is copied to the HalconVCDlg.cpp.

The most important part below is to copy the code in the action to OnBnClickedButton1 () so that clicking the button will perform the display image function implemented in Halcon.

Two variables defined in the action function
Hobject Ho_image;
In order to use these two variables in the response function of Button1, it was previously blog post to define it as a member variable of the dialog class in HalconVCDlg.h, in fact directly defined in void Chalconvcdlg::onbnclickedbutton1 () There is no problem in the function or in the HalconVCDlg.cpp file, but it is not possible to define an out-of-class variable in HalconVCDlg.h as a halconvcdlg.
With this in mind, we can simply copy everything in the action function into OnBnClickedButton1 ().
  Local iconic variables   hobject  ho_image;  Local control Variables   htuple  hv_windowhandle;  Readimage (&ho_image, "c:/users/lenovo/desktop/test.jpg");  Dev_open_window_fit_image (ho_image, 0, 0,-1,-1, &hv_windowhandle);  if (Hdevwindowstack::isopen ())    ClearWindow (Hdevwindowstack::getactive ());  if (Hdevwindowstack::isopen ())    dispobj (Ho_image, hdevwindowstack::getactive ());
Run results

Button1 will pop up a window to show our pictures (yes, it's a desktop).

All program code

MFC programs in HalconVCDlg.h

//HalconVCDlg.h: Header file #pragma once//header file related to Halcon # include "Halconcpp.h" using namespace halconcpp;//Chalconvcdlg The dialog class Chalconvcdlg:public cdialogex{//constructs Public:chalconvcdlg (cwnd* pparent = NULL);//variables used in the standard constructor//halcon, Why define a variable//hobject ho_image;//htuple hv_windowhandle;//dialog box data in a class enum {IDD = idd_halconvc_dialog};p rotected:virtual Voi D DoDataExchange (cdataexchange* PDX);//DDX/DDV support//implement PROTECTED:HICON m_hicon;//generated message map function virtual BOOL OnInitDialog (); afx_msg void OnSysCommand (UINT NID, LPARAM LPARAM), afx_msg void OnPaint (), afx_msg hcursor Onquerydragicon ();D eclare_ Message_map () public:afx_msg void OnBnClickedButton1 ();}; void Dev_open_window_fit_image (Hobject ho_image, Htuple hv_row, Htuple hv_column, Htuple hv_widthlimit, HTuple Hv_Hei Ghtlimit, Htuple *hv_windowhandle); 
MFC programs in HalconVCDlg.cpp
HalconVCDlg.cpp: Implement file # include "stdafx.h" #include "HalconVC.h" #include "HalconVCDlg.h" #include "afxdialogex.h"// Header files related to Halcon # include "Halconcpp.h" #ifdef _debug#define new debug_new#endifusing namespace Halconcpp;
The middle omits a bunch of system-generated functions, here's our main change
  
Procedures//chapter:develop//short Description:open A new graphics window that preserves the aspect ratio of the G Iven image. void Dev_open_window_fit_image (Hobject ho_image, Htuple hv_row, Htuple hv_column, Htuple hv_widthlimit, HTuple Hv_Hei  Ghtlimit, Htuple *hv_windowhandle) {//Local control Variables Htuple hv_minwidth, hv_maxwidth, hv_minheight;  Htuple hv_maxheight, Hv_resizefactor, Hv_imagewidth, hv_imageheight;  Htuple hv_tempwidth, Hv_tempheight, Hv_windowwidth, hv_windowheight; This procedure opens a new graphics window and adjusts the size//such, it fits into the limits specified by WIDTHL  Imit//and Heightlimit, but also maintains the correct image aspect ratio. If it is impossible to match the minimum and maximum extent requirements//at the same time (F.E. If the image is V ery long but narrow),//the maximum value gets a higher priority,////parse input tuple Widthlimit if (0! = (htuple ( Hv_widthlimit.tuplelength ()) ==0). Tupleor (hv_widthlimit<0)) {hv_minwidth = 500;  Hv_maxwidth = 800;    } else if (0! = ((Hv_widthlimit.tuplelength ()) ==1)) {hv_minwidth = 0;  Hv_maxwidth = Hv_widthlimit;    } else {hv_minwidth = ((const htuple&) hv_widthlimit) [0];  Hv_maxwidth = ((const htuple&) hv_widthlimit) [1]; }//parse Input Tuple Heightlimit if (0! = (htuple (hv_heightlimit.tuplelength ()) ==0).    Tupleor (hv_heightlimit<0)) {hv_minheight = 400;  Hv_maxheight = 600;    } else if (0! = ((Hv_heightlimit.tuplelength ()) ==1)) {hv_minheight = 0;  Hv_maxheight = Hv_heightlimit;    } else {hv_minheight = ((const htuple&) hv_heightlimit) [0];  Hv_maxheight = ((const htuple&) hv_heightlimit) [1];  }////test, if window size have to is changed.  Hv_resizefactor = 1;  GetImageSize (Ho_image, &hv_imagewidth, &hv_imageheight);  First, expand window to the minimum extents (if necessary). if (0! = (htuple (hv_minwidth>hv_imagewidth). Tupleor (hv_minheight>hv_imageheight))) {Hv_resizefactor = (((Hv_minwidth.tuplereal ())/hv_imagewidth). Tupleconcat ((Hv_minheight.tuplereal ())/hv_imageheight)).  Tuplemax ();  } hv_tempwidth = Hv_imagewidth*hv_resizefactor;  Hv_tempheight = Hv_imageheight*hv_resizefactor;  Then, the shrink window to maximum extents (if necessary). if (0! = (htuple (hv_maxwidth

Halcon11 and VS2010 co-development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.