建立vc++控制台程序
添加代码如下:
#include "stdafx.h" #include "HalconCpp.h" #include <iostream> using namespace Halcon; using namespace std; int main(int argc, char *argv[]) { cout << "-------------------------------" << endl; cout << "Example program for HALCON/C++:" << endl; cout << "-------------------------------" << endl; cout << "- read image <monkey>" << endl; cout << "- open graphics window" << endl; cout << "- segmentation of the eyes" << endl << endl; HRegionArray Eyes; // result of the segmentation HByteImage Mandrill("monkey"); // read input image HWindow w(0,0,Mandrill.Width(),Mandrill.Height()); // open window w.SetPart(0,0,Mandrill.Height()-1,Mandrill.Width()-1); Mandrill.Display (w); // display the Mandrill HRegionArray regs = (Mandrill >= 128).Connection(); // find bright regions for (long i = 0; i < regs.Num(); i++) // check each region { if ((regs[i].Area() > 500) && // for minimum size (regs[i].Area() < 50000) && // for maximum size (regs[i].Anisometry() < 1.7)) // and shape { Eyes.Append(regs[i]); // add found region to the list } } w.SetColor("red"); // prepare display of regions w.SetDraw("margin"); w.SetLineWidth(3); (Eyes.FillUp() << 9).Display(w); // expand filled eyes and display w.Click(); // wait for mouse click cout << "The End." << endl; return(0); }
运行结果如下:
通过该例程,我们可以得出在vc中使用Halcon时,通过Halcon提供的类函数处理数据,遵循c++的语法知识。