* This example shows how to employ the new extensions of HALCON's variation model operators
* to perform customary print quality tests.
* In this example the variation model is built upon a single reference image.
* The example consists of three steps:
* 1. align the print objects similar to the reference image using a shape-based model
* 2. define the variation image by smoothing the object's contours
* 3. create the variation model
* Whether a print is labelled as OK or not, depends upon the size (area) of the difference to the reference image
*

dev_close_window ()

*读取图片

read_image (Image, 'pen/pen-01')

*获取大小

get_image_size (Image, Width, Height)

*打开窗口

dev_open_window (0, 0, Width, Height, 'black', WindowHandle)

*关闭窗口更新

dev_update_off ()

*设置字体

set_display_font (WindowHandle, 12, 'courier', 'true', 'false')

*显示图片

dev_display (Image)


* segment the logo and create a shape model for the alignment

*二值化图片

threshold (Image, Region, 125, 255)

*填充图片

fill_up (Region, RegionFillUp)

*计算两图片的不同,得到中间灰色有图像的部分.

difference (RegionFillUp, Region, RegionDifference)

*将区域进行凸包变换

shape_trans (RegionDifference, LogoArea, 'convex')

*肿胀区域,图片reduce区域处理完成

dilation_circle (LogoArea, LogoArea, 7)

*将图片重新剪切为有显示的区域.

reduce_domain (Image, LogoArea, ImageReduced)

*创建模板

create_shape_model (ImageReduced, 'auto', -rad(10), rad(20), 'auto', 'auto', 'use_polarity', [40,50], 40, ShapeModelID)

*计算中心点和面积

area_center (LogoArea, Area, ModelRow, ModelColumn)


* define the variation image by smoothing the dilated regions obtained from the object's contours:
* Besides a binomial filter a neat trick is applied to get smoothly "polished" regions along the contours.
* In particular, the edges are enlarged and after their conversion into a dilated region the image

* is zoomed back to its original size using a weighting that smoothes the images further.

*亚像素分割图片

edges_sub_pix (ImageReduced, Edges, 'sobel_fast', 0.5, 10, 20)

*创建一个变换矩阵

hom_mat2d_identity (HomMat2DIdentity)

*矩阵x,y放大

hom_mat2d_scale (HomMat2DIdentity, 4, 4, 0, 0, HomMat2DScale)

*变换矩阵

affine_trans_contour_xld (Edges, ZoomedEdges, HomMat2DScale)

*产生空白图片

gen_image_const (VarImageBig, 'byte', 4*Width, 4*Height)

*计算XLD的对象

count_obj (ZoomedEdges, NEdges)

for i := 1 to NEdges by 1

*选择对象

select_obj (ZoomedEdges, ObjectSelected, i)

*得到XLD的XY坐标点集

get_contour_xld (ObjectSelected, RowEdge, ColEdge)

*根据XLD坐标点集生成多边形

gen_region_polygon (Region1, RowEdge, ColEdge)

*肿胀区域,变得圆滑一些.

dilation_circle (Region1, RegionDilation, 2.5)

*将区域画到新的空图片上.

paint_region (RegionDilation, VarImageBig, VarImageBig, 255, 'fill')

endfor

*压缩图片大小及正常大小

zoom_image_size (VarImageBig, VarImageSmall, Width, Height, 'weighted')

*binomial平滑图片

binomial_filter (VarImageSmall, VarImage, 3, 3)

*建立一个可变化比较模板

create_variation_model (Width, Height, 'byte', 'direct', VarModelID)

*将image图片转换为可变化比较模板VarModelID

prepare_direct_variation_model (Image, VarImage, VarModelID, 15, 4)

*显示这个模板

dev_display (VarImage)

disp_message (WindowHandle, 'Variation Image', 'window', -1, -1, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*

* print inspection

*以下开始比较图片了

for i := 1 to 30 by 1

*读取图片

read_image (Image, 'pen/pen-'+i$'02d')

* locate the logo and align it to the reference image

* 通过模板查找目标目标位置坐标和角度

find_shape_model (Image, ShapeModelID, -rad(10), rad(20), 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)

if (|Score| # 0)

*找到了目标,就刚性变换

vector_angle_to_rigid (Row, Column, Angle, ModelRow, ModelColumn, 0, HomMat2D)

affine_trans_image (Image, ImageAffinTrans, HomMat2D, 'constant', 'false')

*剪切图片

reduce_domain (ImageAffinTrans, LogoArea, ImageReduced1)

* 开始比较

compare_ext_variation_model (ImageReduced1, RegionDiff, VarModelID, 'absolute')

*连通区域

connection (RegionDiff, ConnectedRegions)

*通过面积选择区域,忽略太小的点啊啥的.

select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 10, 99999)

*以下开始显示结果了

dev_display (ImageAffinTrans)

*计算查找到的不同区域个数并显示ng or pass

count_obj (SelectedRegions, NDefects)
        if (NDefects > 0)
            dev_set_color ('red')
            dev_set_draw ('margin')
            dev_set_line_width (2)
            dev_display (SelectedRegions)
            dev_set_color ('green')
            dev_set_line_width (1)
            dev_display (Edges)
            disp_message (WindowHandle, 'Image check not OK', 'window', -1, -1, 'red', 'false')
        else
            disp_message (WindowHandle, 'Image check OK', 'window', -1, -1, 'green', 'false')
        endif
    endif
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
endfor
*

* clean up

*最后记得要清理垃圾

clear_shape_model (ShapeModelID) 
clear_variation_model (VarModelID)

halcon中variation_model_single实例注释.的更多相关文章

  1. Photoshop和Halcon中的极坐标变换

    极坐标想必学过高中数学的人都听过,一般的坐标系中用(x, y)值来描述一个点的位置,而在极坐标系中,则使用到原点的距离ρ和夹角θ来描述该点的位置. 我很早就接触了Photoshop,知道Photosh ...

  2. HALCON中的算子大全(中英对照)

    HALCON中的算子大全(中英对照) Chapter 1 :Classification1.1 Gaussian-Mixture-Models1.add_sample_class_gmm功能:把一个训 ...

  3. 使用.NET中的XML注释(二) -- 创建帮助文档入门篇

    一.摘要 在本系列的第一篇文章介绍了.NET中XML注释的用途, 本篇文章将讲解如何使用XML注释生成与MSDN一样的帮助文件.主要介绍NDoc的继承者:SandCastle. 二.背景 要生成帮助文 ...

  4. C# 在PDF中添加墨迹注释Ink Annotation

    PDF中的墨迹注释(Ink Annotation),表现为徒手涂鸦式的形状:该类型的注释,可任意指定形状顶点的位置及个数,通过指定的顶点,程序将连接各点绘制成平滑的曲线.下面,通过C#程序代码介绍如何 ...

  5. 【短道速滑九】仿halcon中gauss_filter小半径高斯模糊优化的实现

    通常,我们谈的高斯模糊,都知道其是可以行列分离的算法,现在也有着各种优化算法实现,而且其速度基本是和参数大小无关的.但是,在我们实际的应用中,我们可能会发现,有至少50%以上的场景中,我们并不需要大半 ...

  6. 【转】代码中特殊的注释技术——TODO、FIXME和XXX的用处

    (转自:http://blog.csdn.net/reille/article/details/7161942) 作者:reille 本博客网址:http://blog.csdn.net/reille ...

  7. jsp的 javascript中 嵌套 html 注释

    看到公司的代码,我也是蛋疼了,各种乱. 还发现有很多的jsp的 javascript中 嵌套 html 注释, 这个可行? 我之前可是没用过. 后面查找各种资料发现,这个也是可行的,主要是为了兼容不支 ...

  8. 关于Javascript中通过实例对象修改原型对象属性值的问题

    Javascript中的数据值有两大类:基本类型的数据值和引用类型的数据值. 基本类型的数据值有5种:null.undefined.number.boolean和string. 引用类型的数据值往大的 ...

  9. JScript中的条件注释详解(转载自网络)

    JScript中的条件注释详解-转载 这篇文章主要介绍了JScript中的条件注释详解,本文讲解了@cc_on.@if.@set.@_win32.@_win16.@_mac等条件注释语句及可用于条件编 ...

随机推荐

  1. [SmartFoxServer概述]SFS2X特点

    SFS2X 特点概述 SFS2X采用SFS核心原理并在新的方向进行扩展,介绍了许多改善方案,同时专注于几个方面:使用简单化,通用化和性能化. *使用简单化:清除了SFS之前版本中所有不必要的复杂方法, ...

  2. Windows 8.1 应用再出发 - 创建我的第一个应用

    转眼间Windows 8.1已经发布了四个多月,之前因为开发需要对Windows 8.1新特性进行过零散的学习和使用,一直没有静下心来系统的学习过.近日部门有几名新同事加入,需要进行Windows 商 ...

  3. day7----面向对象编程进阶

    本节内容: 面向对象高级语法部分 静态方法.类方法.属性方法 类的特殊方法 反射 异常处理 Socket开发基础 静态方法 它与类唯一的关联就是需要通过类名来调用这个方法 #静态方法实际跟类没关系,不 ...

  4. 禁用 WebView 放大镜及拷贝粘贴弹出框

    文/KyXu(简书作者)原文链接:http://www.jianshu.com/p/40048d9c979a著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 背景:当你的App中有 We ...

  5. 【转载】关于Linux Shell 特殊字符

    一.通配符     1.一般通配符       ① * (星号):匹配字符的0次或多次出现       举例:f*可以匹配f.fa.fls.a     注意:“.”和“/”必须显示匹配         ...

  6. 用c#开发微信 (11) 微统计 - 阅读分享统计系统 1 基础架构搭建

    微信平台自带的统计功能太简单,有时我们需要统计有哪些微信个人用户阅读.分享了微信公众号的手机网页,以及微信个人用户访问手机网页的来源:朋友圈分享访问.好友分享消息访问等.本系统实现了手机网页阅读.分享 ...

  7. ubuntu adobe flash player 安装

    常规做法 1.先更新sudo apt-get update 2. sudo apt-get install flashplugin-installer 这次却卡在downloading这里 下不去.无 ...

  8. 【ASP.NET Web API教程】6.3 内容协商

    本文是Web API系列教程的第6.3小节 6.3 Content Negotiation 6.3 内容协商 摘自:http://www.asp.net/web-api/overview/format ...

  9. Hadoop HDFS 架构设计

    HDFS 简介 Hadoop Distributed File System,简称HDFS,是一个分布式文件系统. HDFS是高容错性的,可以部署在低成本的硬件之上,HDFS提供高吞吐量地对应用程序数 ...

  10. CSS设计资料

    CSS实现垂直居中的5种方法 网页阶级配色:http://tools.jb51.net/tools/peise.htm