PLC论坛-全力打造可编程控制器专业技术论坛

 找回密码
 注册哦

QQ登录

只需一步,快速开始

微信扫码登录

查看: 2602|回复: 0

halcon中基于灰度的模板匹配方法

[复制链接]
发表于 2010-4-8 10:11:00 | 显示全部楼层 |阅读模式
下面是halcon生成的C++代码,耗时11S,结果不准确,看来也不能迷信HALCON。 /////////////////////////////////////////////////////////////////////////////// // File generated by HDevelop for HALCON/C++ Version 8.0 /////////////////////////////////////////////////////////////////////////////// #include "HalconCpp.h" #ifndef NO_EXPORT_MAIN // Main procedure void action() { using namespace Halcon; // Local iconic variables Hobject Image, Image1, Rectangle, ImageReduced; Hobject Region, RegionDilation, Pattern, Matches, ConnectedMatches; Hobject GrayRegions; // Local control variables HTuple Width1, Height1, Width, Height, WindowID; HTuple TemplateID, Row, Column, Error, i; //Search all good matches of a pattern in an image of letters // // dev_close_window(); no window open in C++ read_image(&Image, "D:/Documents and Settings/nyist/My Documents/Visual Studio 2008/Projects/MoreFastMutualInformation/MoreFastMutualInformation/left.bmp"); read_image(&Image1, "D:/Documents and Settings/nyist/My Documents/Visual Studio 2008/Projects/MoreFastMutualInformation/MoreFastMutualInformation/right.bmp"); get_image_pointer1(Image1, _, _, &Width1, &Height1); get_image_pointer1(Image, _, _, &Width, &Height); set_window_attr("background_color","black"); open_window(0,0,(Width1/4)*3,(Height1/4)*3,0,"","",&WindowID); gen_rectangle1(&Rectangle, 200, 425, 260, 550); reduce_domain(Image, Rectangle, &ImageReduced); threshold(ImageReduced, &Region, 50, 150); dilation_circle(Region, &RegionDilation, 5.0); reduce_domain(Image, RegionDilation, &Pattern); //Preparing a pattern for template matching create_template(Pattern, 255, 4, "sort", "original", &TemplateID); fast_match_mg(Image1, &Matches, TemplateID, 40, 3); connection(Matches, &ConnectedMatches); add_channels(ConnectedMatches, Image1, &GrayRegions); //Search the best matches of the character pattern best_match(GrayRegions, TemplateID, 20, "true", &Row, &Column, &Error); disp_obj(Image1, WindowID); set_color(WindowID,"red"); //Display a circle on the position of the best match for (i=0; i<=(Row.Num())-1; i+=1) { if (HTuple(Error)<255) { disp_circle(WindowID, HTuple(Row), HTuple(Column), 10.5); } } } #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
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册哦

本版积分规则

QQ|小黑屋|手机版|Archiver|PLC技术网-PLC论坛 ( 粤ICP备17165530号 )|网站地图

GMT+8, 2024-9-19 08:57 , Processed in 0.046499 second(s), 24 queries .

快速回复 返回顶部 返回列表