* This example program shows how to use HALCON's shape-based matching
* to find multiple different models in one call to find_shape_models. Note that this
* is one mode of operation that is frequently useful. However, the number of
* applications that can be solved with this mechanism is much larger. For
* another application where finding multiple models in one call is useful are
* applications where the same object can only occur in small angle ranges
* around a discrete set of angles, e.g., 0°, 90°, 180°, and 270°. In these cases,
* it would be wasteful to train the model for the full 360° rotation range and to
* match the model in this range. Instead, four models using the small angle
* ranges around the discrete set of angles should be generated from the same
* model image and used in the matching stage using four different angle ranges.
dev_update_pc ('off')
dev_update_window ('off')
dev_update_var ('off')
dev_close_window ()
dev_open_window (0, 0, 646, 482, 'black', WindowHandle)
dev_set_part (0, 0, 481, 645)
set_display_font (WindowHandle, 20, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
* These colors will be used to graphically discern the different models in the
* visualization code below.
Colors := ['red','green','cyan']
* The models will be generated from hard-coded rectangles given by the
* following coordinates:
Row1 := [135,150,185]
Column1 := [250,170,220]
Row2 := [375,310,335]
Column2 := [355,395,375]
* The object Models will hold a set of XLD contours that represent the different
* models. They are used below to overlay the found models on the current
* image. XLD contours are used because they can be transformed much faster
* than regions. This creates a slight problem because in general multiple XLD
* contours will represent one model. Therefore, the start and end indices of the
* different models will be stored in IndexS and IndexE, respectively.
gen_empty_obj (Models)
IndexS := []
IndexE := []
* The variable ModelIDs holds the different models that are created below.
ModelIDs := []
* Likewise, RowsRef and ColumnsRef store the reference points of the different
* models. They are necessary to transform the models to the found instances
* in the current image.
for J := 1 to 3 by 1
read_image (Image, 'metal-parts/metal-part-model-' + J$'02d')
dev_display (Image)
dev_set_color ('green')
set_tposition (WindowHandle, 20, 20)
write_string (WindowHandle, 'Generating shape model ' + J$'d')
gen_rectangle1 (Rectangle, Row1[J - 1], Column1[J - 1], Row2[J - 1], Column2[J - 1])
area_center (Rectangle, Area, Row, Column)
reduce_domain (Image, Rectangle, ImageReduced)
* Although we will use get_shape_model_contours below to obtain the
* representation of the model, we extract a model representation here using
* inspect_shape_model because this enables us to display the representation
* of the model while the model is being created.
inspect_shape_model (Image, ModelImages, ModelRegions, 1, 30)
* Since the shape models contain a few extraneous edges, they will be
* removed here to give a slightly nicer visualization.
connection (ModelRegions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 20, 100000)
union1 (SelectedRegions, ModelRegions)
gen_contours_skeleton_xld (ModelRegions, ModelContours, 1, 'filter')
dev_set_color ('red')
dev_display (ModelContours)
create_shape_model (ImageReduced, 5, rad(0), rad(360), 'auto', 'pregeneration', 'use_polarity', 30, 7, ModelID)
get_shape_model_contours (ModelCont, ModelID, 1)
select_shape_xld (ModelCont, ModelContours, 'contlength', 'and', 20, 1000)
* Count how many XLD contours there are in the current model and in the
* already stored models. This is necessary to compute IndexS and IndexE.
count_obj (ModelContours, NumModel)
count_obj (Models, NumModels)
concat_obj (Models, ModelContours, Models)
IndexS := [IndexS,NumModels + 1]
IndexE := [IndexE,NumModels + NumModel]
ModelIDs := [ModelIDs,ModelID]
endfor
dev_set_color ('yellow')
set_tposition (WindowHandle, 50, 20)
write_string (WindowHandle, 'Press left button to start')
set_tposition (WindowHandle, 80, 20)
write_string (WindowHandle, 'and stop the demo.')
get_mbutton (WindowHandle, Row3, Column3, Button1)
wait_seconds (0.5)
dev_set_color ('red')
Button := 0
ImgNo := 1
while (Button != 1)
read_image (Image, 'metal-parts/metal-parts-' + ImgNo$'02d')
count_seconds (S1)
find_shape_models (Image, ModelIDs, rad(0), rad(360), 0.6, 0, 0.5, 'least_squares', 0, 0.6, Row, Column, Angle, Score, Model)
count_seconds (S2)
Time := (S2 - S1) * 1000
dev_display (Image)
Num := |Score|
for J := 0 to Num - 1 by 1
* Select the correct XLD contours from the Models object.
copy_obj (Models, ModelSelected, IndexS[Model[J]], IndexE[Model[J]] - IndexS[Model[J]] + 1)
* Compute the transformation from the model object to the current instance.
vector_angle_to_rigid (0, 0, 0, Row[J], Column[J], Angle[J], HomMat2D)
affine_trans_contour_xld (ModelSelected, ModelTrans, HomMat2D)
dev_set_color (Colors[Model[J]])
dev_display (ModelTrans)
endfor
dev_set_color ('yellow')
set_tposition (WindowHandle, 20, 20)
if (Num == 1)
write_string (WindowHandle, Num$'1d' + ' object found in ' + Time$'4.2f' + 'ms')
else
write_string (WindowHandle, Num$'1d' + ' objects found in ' + Time$'4.2f' + 'ms')
endif
ImgNo := ImgNo + 1
if (ImgNo > 15)
ImgNo := 1
endif
dev_error_var (Error, 1)
dev_set_check ('~give_error')
get_mposition (WindowHandle, R, C, Button)
dev_error_var (Error, 0)
dev_set_check ('give_error')
if (Error != H_MSG_TRUE)
Button := 0
endif
endwhile
for J := 0 to |ModelIDs| - 1 by 1
clear_shape_model (ModelIDs[J])
endfor

示例:pm_multiple_models 匹配——形状匹配的更多相关文章

  1. HALCON形状匹配讲解

    HALCON形状匹配讲解 https://blog.csdn.net/linnyn/article/details/50663328 https://blog.csdn.net/u014608071/ ...

  2. (转)基于形状匹配的Halcon算子create_shape_model

    HDevelop开发环境中提供的匹配的方法主要有三种,即Component-Based.Gray-Value-Based.Shape-Based,分别是基于组件(或成分.元素)的匹配,基于灰度值的匹配 ...

  3. 正则双重过滤 /// splitKey1 第一个正则式匹配 /// splitKey2 匹配结果中再次匹配进行替

    /// <summary> /// 正则双重过滤 /// splitKey1 第一个正则式匹配 /// splitKey2 匹配结果中再次匹配进行替换 /// </summary&g ...

  4. HALCON形状匹配(转)

    LIntExport Herror create_shape_model( const Hobject&  Template ,  //reduce_domain后的模板图像 Hlong  N ...

  5. 基本例程(4-1)手势识别C++ 和简单形状匹配

    扩展库https://blog.csdn.net/Taily_Duan/article/details/52130135 opencv3.3+扩展库 /************************ ...

  6. mysql like 贪婪匹配 同时匹配多个值

    LIKE "%a%b%c%",这样匹配出的就是包含a,b,c三个关键词的记录  (三个关键词不在一起时) 不好用 mysql> select count(1) from dm ...

  7. HDU 3729 二分匹配 反向匹配

    题意: 给定 n个学生 说的 自己 考试排名的 可能范围 确定最多几个人说真话 如果有多种答案,输出字典序最大的那种( 要求字典序最大,所以solve中从最大字典序开始匹配) 思路: 题目给定  点 ...

  8. python opencv3 基于ORB的特征检测和 BF暴力匹配 knn匹配 flann匹配

    git:https://github.com/linyi0604/Computer-Vision bf暴力匹配: # coding:utf-8 import cv2 """ ...

  9. 【转】字符串匹配的KMP算法:移动位数 = 已匹配 - 部分匹配值(共有长度)

    计算机的基本任务之一. 举例来说,有一个字符串"BBC ABCDAB ABCDABCDABDE",我想知道,里面是否包含另一个字符串"ABCDABD"? 许多算 ...

随机推荐

  1. spring(二、bean生命周期、用到的设计模式、常用注解)

    spring(二.bean生命周期.用到的设计模式.常用注解) Spring作为当前Java最流行.最强大的轻量级框架,受到了程序员的热烈欢迎.准确的了解Spring Bean的生命周期是非常必要的. ...

  2. MacBook使用笔记2 - 安装windows虚拟机攻略

    转载请标注原链接:http://www.cnblogs.com/xczyd/p/5498878.html 5月初从阿里滚粗,然后失去了公司发的Mac Air.说实话Mac机器确实比windows好用一 ...

  3. webpack的入门教程

    webpack是模块打包工具/前端资源加载.它是根据模块的依赖关系进行静态分析,然后将这些模块按照指定的规则生成对应的静态资源. webpack可以将css.less.js转换为一个静态文件,减少了页 ...

  4. 2017《JAVA技术》预备作业-计科1502-19-何俏依

    1.阅读邹欣老师的博客,谈谈你期望的师生关系是什么样的? 我期望的师生关系是长辈和晚辈,前辈和后生,朋友与朋友之间的关系,作为晚辈,要尊敬长辈,不能对长辈进行言语攻击和起冲突:作为后生,要谨遵教诲,有 ...

  5. springdata笔记

    SpringData整合hibernate CRUD操作: applicationContext.xml: <?xml version="1.0" encoding=&quo ...

  6. ex_BSGS

    //author Eterna #define Hello the_cruel_world! #pragma GCC optimize(2) #include<iostream> #inc ...

  7. BEAM188和LINK180简单实例

    简介 一开始想做一个绳索单元悬挂重物的仿真,其实想法很简单,但是在实现过程中却出现了很大的问题,纠结了很久,初步归结为:绳索单元在垂直其单元方向上受力,会导致其产生很大的变形,从而导致其不收敛.因此专 ...

  8. 在windows上使用ssh秘钥连接git服务器

    git部署在centos7上 安装好git后,新建一个用户test(注意要加入git用户组)配置ssh秘钥登录,我的另一篇博客有写配置步骤 重点的地方是在windows系统上使用秘钥登录git服务器 ...

  9. 二、tcp/ip基础知识

    一.TCP/IP的标准化 1.TCP/IP的含义 一般来说,TCP/IP是利用IP进行通信时所必须用到的协议群的统称. 具体点,IP或ICMP.TCP或UDP.TELENT或FTP.以及HTTP等都属 ...

  10. type=number 的maxlength和可以输入E的问题

    有一个输入框,要求只能输入1到999以下数字,于是 设置<input type="number" min="1" max="999"& ...