如何在vc++中调用halcon的hdev档案
2015-05-26 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517184
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
vc使用halcon
使用hdevelop导出halcon程序的c++代码之后,比如
[cpp] view plaincopyread_image (image, 'C:/Documents and Settings/Administrator/桌面/vision/IMG_20121015_091436.bmp')
rgb1_to_gray (image, GrayImage)
dev_set_color('blue')
*bin_threshold (GrayImage, Region)
threshold(GrayImage,Region,100,255)
area_center (Region, Area, Row, Column)
生成c++代码
[cpp] view plaincopy///////////////////////////////////////////////////////////////////////////////
// File generated by HDevelop for HALCON/C++ Version 10.0
///////////////////////////////////////////////////////////////////////////////
#include "HalconCpp.h"
using namespace Halcon;
#ifndef NO_EXPORT_MAIN
// Main procedure
void action()
{
using namespace Halcon;
// Local iconic variables
Hobject image, GrayImage, Region;
// Local control variables
HTuple Area, Row, Column;
read_image(&image, "C:/Documents and Settings/Administrator/桌面/vision/IMG_20121015_091436.bmp");
rgb1_to_gray(image, &GrayImage);
if (HDevWindowStack::IsOpen())
set_color(HDevWindowStack::GetActive(),"blue");
bin_threshold(GrayImage, &Region);
area_center(Region, &Area, &Row, &Column);
}
#ifndef NO_EXPORT_APP_MAIN
int main(int argc, char *argv[])
{
using namespace Halcon;
// Default settings used in HDevelop (can be omitted)
set_system("do_low_error","false");
action();
return 0;
}
#endif
#endif
新建一个对话框mfc程序(vc2008),添加一个按钮button1,加入如下代码(我将action函数稍微改了一下)
当然先要#include "HalconCpp.h"
[cpp] view plaincopy// Main procedure
double action( char * p)
{
using namespace Halcon;
// Local iconic variables
Hobject image, GrayImage, Region;
// Local control variables
HTuple Area, Row, Column;
read_image(&image, p);
rgb1_to_gray(image, &GrayImage);
if (HDevWindowStack::IsOpen())
set_color(HDevWindowStack::GetActive(),"blue");
//bin_threshold(GrayImage, &Region);
threshold(GrayImage, &Region,50,255);
area_center(Region, &Area, &Row, &Column);
double d=Area[0];
return d;
}
void CabcDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
double d=action("C:/Documents and Settings/Administrator/桌面/vision/IMG_20121015_091436.bmp");
CString str;
str.Format("%f",d);
AfxMessageBox(str);
}
编译程序之前需要先设置一下include和链接环境,对于vc2008
工具/选项/项目解决方案/vc++目录/包含文件/ 添加
C:\Program Files\MVTec\HALCON-10.0\include
C:\Program Files\MVTec\HALCON-10.0\include\cpp
工具/选项/项目解决方案/vc++目录/库文件/ 添加
C:\Program Files\MVTec\HALCON-10.0\lib\x86sse2-win32
然后执行即可。
使用hdevelop导出halcon程序的c++代码之后,比如
[cpp] view plaincopyread_image (image, 'C:/Documents and Settings/Administrator/桌面/vision/IMG_20121015_091436.bmp')
rgb1_to_gray (image, GrayImage)
dev_set_color('blue')
*bin_threshold (GrayImage, Region)
threshold(GrayImage,Region,100,255)
area_center (Region, Area, Row, Column)
生成c++代码
[cpp] view plaincopy///////////////////////////////////////////////////////////////////////////////
// File generated by HDevelop for HALCON/C++ Version 10.0
///////////////////////////////////////////////////////////////////////////////
#include "HalconCpp.h"
using namespace Halcon;
#ifndef NO_EXPORT_MAIN
// Main procedure
void action()
{
using namespace Halcon;
// Local iconic variables
Hobject image, GrayImage, Region;
// Local control variables
HTuple Area, Row, Column;
read_image(&image, "C:/Documents and Settings/Administrator/桌面/vision/IMG_20121015_091436.bmp");
rgb1_to_gray(image, &GrayImage);
if (HDevWindowStack::IsOpen())
set_color(HDevWindowStack::GetActive(),"blue");
bin_threshold(GrayImage, &Region);
area_center(Region, &Area, &Row, &Column);
}
#ifndef NO_EXPORT_APP_MAIN
int main(int argc, char *argv[])
{
using namespace Halcon;
// Default settings used in HDevelop (can be omitted)
set_system("do_low_error","false");
action();
return 0;
}
#endif
#endif
新建一个对话框mfc程序(vc2008),添加一个按钮button1,加入如下代码(我将action函数稍微改了一下)
当然先要#include "HalconCpp.h"
[cpp] view plaincopy// Main procedure
double action( char * p)
{
using namespace Halcon;
// Local iconic variables
Hobject image, GrayImage, Region;
// Local control variables
HTuple Area, Row, Column;
read_image(&image, p);
rgb1_to_gray(image, &GrayImage);
if (HDevWindowStack::IsOpen())
set_color(HDevWindowStack::GetActive(),"blue");
//bin_threshold(GrayImage, &Region);
threshold(GrayImage, &Region,50,255);
area_center(Region, &Area, &Row, &Column);
double d=Area[0];
return d;
}
void CabcDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
double d=action("C:/Documents and Settings/Administrator/桌面/vision/IMG_20121015_091436.bmp");
CString str;
str.Format("%f",d);
AfxMessageBox(str);
}
编译程序之前需要先设置一下include和链接环境,对于vc2008
工具/选项/项目解决方案/vc++目录/包含文件/ 添加
C:\Program Files\MVTec\HALCON-10.0\include
C:\Program Files\MVTec\HALCON-10.0\include\cpp
工具/选项/项目解决方案/vc++目录/库文件/ 添加
C:\Program Files\MVTec\HALCON-10.0\lib\x86sse2-win32
然后执行即可。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询