HALCON基础知识
HALCON
1. 语法范式 Syntax Style
1.1. 基本格式
1.1.1. 算子格式
算子(输入图像参数:输出图像参数:输入控制参数:输出控制参数)
其中四个参数任意一个可以为空
e.g.1.threshold(Image : Region : MinGray, MaxGray : )
** threshold算子,1 Image Para input : Image ; 2 Image Para output :Region ;
**3 Control Para input : MinGray , MaxGray 4 Control Para output :无
2.get_image_pointer1(Image : : : Pointer, Type, Width, Height)
** threshold算子,1 Image Para input : Image ; 2 Image Para output :无;
** 3 Control Para input : 无 4 Control Para output : Pointer, Type, Width, Height
1.1.2. 程序结构
HDEV即HALCON Develop,相当于VC中sln,solution。dev下面有很多窗口。
Switches the update of the PC during program execution on or off.
Switch time measurement for operators on or off.
Switches the update of the variable window during program execution on or off.
Switches the automatic output of iconic output objects into the graphics window during program execution on or off.
1.1.3. 符号
这里主要列出一些和C/C++含义不同的符号,以及HALCON中一些重要符号。
|
编号 |
符号 |
符号含义 |
|
1 |
* |
注释符号 |
|
2 |
:= |
赋值符号,和C中不同 |
|
3 |
= |
逻辑符号,判断相等,相对于C中的’==’ |
|
4 |
\ |
转义符号,至少可以在用于换行的转义,’\+Enter’就可以续行了 |
|
5 |
$ |
变量指示符号,e.g. +Distance$'.3'表示将变量Distance写成3个字长的字符串形式 |
|
6 |
F1 |
Help文档,直接看算子 |
|
7 |
F2 |
回滚到程序头 |
|
8 |
F3/F4 |
激活/注销此行代码 |
|
9 |
F5 |
运行程序 |
|
10 |
F6 |
单步执行 |
|
11 |
F10 |
设置断点 |
1.2. 读写文件I/O
1.2.1. 控制变量的I/O
HACLON的输入,输出写法相当灵活。下面三个列子分别是常量字符串,格式化的浮点数,和一个tuple的输出
*字符串和单个浮点数的输出,甚至不需要fnew_line来写下一行,直接用\n,在一般的文本编辑器里就能有比较好的格式。 注意不用写百分号'%d'
'd',' 3d'表示始终为3位输出,'10.3f'表示始终为10位输出,其中小数位占3位
fwrite_string(FileHandle,'\tR1\tx1\ty1\tR2\tx2\ty2\td1\td2\td3\n')
fwrite_string(FileHandle, '\n'+i$'d'+' '+R1$'10.3f'+x1$'10.3f'+y1$'10.3f'+\
R2$'10.3f'+x2$'10.3f'+y2$'10.3f'+\
d1$'10.3f'+d2$'10.3f'+d3$'10.3f')
*在同一行中输出按'7.3f'的格式输出UpRows的所有元素,元素之间有个空格
fnew_line(FileHandle)
fwrite_string(FileHandle,UpRows$'7.3f'+' ') /
1.2.2. 图像变量的I/O
Path:= 'I:/Work/ritz/Piece/data/data_0528/'
read_image (Image, Path+'hgtest1__'+i$'d')
dump_window (WindowHandle, 'png', 'C:/Documents and Settings/Administrator/桌面/sadaharu2_gray.png')
write_image (Amp, 'png', 0 , 'C:/Documents and Settings/Administrator/桌面/sadaharu2_canny2.png')
write_region(Margin,'C:/Documents and Settings/Administrator/桌面/sadaharu2_canny3.tif')
1.3. 图像或形状的生成与显示
这条主要是为了区分三个系列的函数,gen_ , draw_ 和 disp_
l gen_ gen系列跨度很大,一般属于Creation范畴,生成的可以是图像image,匹配模板model,区域region,轮廓Contour,亚像素级轮廓Contour XLD,滤波器filter,HALCON内部描述文件descr(如标定板的表述caltab10mm.descr)等。下面展示的是一些容易混淆的gen_circle等,都是生成区域,属于Table of Contents/Regions/Creation:
Create a circle.
Create an ellipse.
Create a rectangle of any orientation.
以画圆为例,含有Row,Col,R,且这些都是输入量:
gen_circle( : Circle : Row, Column, Radius : )
l draw_ 属于Table of Contents/Graphics/Drawing和我们平常理解的不同,这里的draw是指交互式地在窗口上画图,而不是直接按参数画图
Interactive drawing of a circle.
Interactive drawing of an ellipse.
Draw a line.
以画圆为例,虽然也有Row,Col,R,但这些都是输出量:
draw_circle( : : WindowHandle : Row, Column, Radius)
l disp_ 属于Table of Contents/Graphics/Output
Displays circular arcs in a window.输出显示一段弧
Displays arrows in a window.输出显示一个箭头
Displays circles in a window.
Displays crosses in a window.
以画弧为例,虽然也有CRow,CCol,而且这些都是输入的控制参数:
disp_arc( : : WindowHandle, CenterRow, CenterCol, Angle, BeginRow, BeginCol : )
2. 数据结构 Data Structure
2.1. Tuple元组
HALCON中的元组是一个涵盖范围很广的数据结构,可以表示各种整形浮点,也可以表示字符串。
2.1.1. tuple的函数
① Tuple的长度
tuple_length( : : Tuple : Length)
e.g.tuple_length( RowsEdges, LengthEdge),还有一种更简单的方法,
② Tuple按index取元素
tuple_select( : : Tuple, Index : Selected)
e.g.tuple_select( RowsEdges, 0,RowSelectedPoint)
tuple_select_range( : : Tuple, Leftindex, Rightindex : Selected)
Select several elements of a tuple between the left index and the right index.
③ Tuple的初始化,包含分配内存需要的长度以及初始值
gen_tuple_const(NumHoles,0)
2.1.2. tuple的操作符
tuple的操作除了调用函数,还可以直接访问元素,或者使用操作符
① Tuple的长度
e.g.LengthEdge1 := |RowsEdges|
② Tuple按index取元素
e.g.RowSelectedPoint := RowsEdges[0]
2.2. 常见图像变量数据结构及相互转换:
Image,Region, Contour ,XLD,几何图形
2.2.1. Image
Region
① Image
Region
threshold(Image : Region : MinGray, MaxGray : )
Bin_threshold,char_threshold,dual_threshold,dyn_threshold,fast_threshold,hysteresis_threshold,threshold_sub_pix
var_threshold Threshold an image by local mean and standard deviation analysis
watersheds_threshold— Extract watershed basins from an image using a threshold.
② Image
Region
reduce_domain(Image, Region : ImageReduced : : )
Reduce the domain of an image.提取ROI中的图像部分
region_to_bin(Region : BinImage : ForegroundGray, BackgroundGray, Width, Height : )
Convert a region into a binary byte-image。将区域转化为二值图
region_to_label(Region : ImageLabel : Type, Width, Height : ) Convert regions to a label image.
region_to_mean(Regions, Image : ImageMean : : )
Paint regions with their average gray value. 结合原图Image将区域内所有像素点转换为它的中值。
2.2.2. Region
Contour
① Region
Contour
Create XLD contours corresponding to circles or circular arcs.
Transforms a NURBS curve into an XLD contour.
gen_contour_polygon_rounded_xld
Generate a XLD contour with rounded corners from a polygon (given as tuples).
Generate an XLD contour from a polygon (given as tuples).
Generate XLD contours from regions.
Convert a skeleton into XLD contours.
Generate one XLD contour in the shape of a cross for each input point.
Creation of an XLD contour corresponding to an elliptic arc.
Create control data of a NURBS curve that interpolates given points.
Extract parallel XLD polygons.
Approximate XLD contours by polygons.
Create an XLD contour in the shape of a rectangle.
Extract parallel XLD polygons enclosing a homogeneous area.
3. 函数理解 Understanding the Basic but Essential Functions
3.1. edges_sub_pix
edges_sub_pix (Image, Edges, 'canny', 0.9, 20, 40)
edges_sub_pix(Image : Edges : Filter, Alpha, Low, High : )
主要介绍Canny边缘检测,同hysteresis_threshold,Canny边缘检测时不是单个阈值,而是有个“迟滞效应”设置了双阈值。
hysteresis_threshold performs a hysteresis threshold operation (introduced by Canny) on an image. All points in the input image Image having a gray value larger than or equal to High are immediately accepted (“secure” points). Conversely, all points with gray values less than Low are immediately rejected. “Potential” points with gray values between both thresholds are accepted if they are connected to “secure” points by a path of “potential” points having a length of at most MaxLength points. This means that “secure” points influence their surroundings (hysteresis).
4. 经验谈 Special Tips
4.1. 多使用help 文档中的Content Table:有问题何不往上翻一级
“不是路上真面目,只缘身在此山中”。解决一个问题,就和了解一个山峰所有真正的登山路一样,当我们在山腰中时,自然是很难了解这条路是否能直通山顶的,而当我们处在一个比这座峰更高的一个位置时,很自然就可以观察或者自己构造出一条比较好的登山路。这就是看往上一级,才看Content Table的作用,在这样一个更高的视野我们就可以找到在这个范围内的其他的路,也许刚好可以登上这座峰。如:
Table of Contents/Filter/smooth_image,
eliminate_min_max : Smooth an image in the spatial domain to suppress noise.
HALCON基础知识的更多相关文章
- .NET面试题系列[1] - .NET框架基础知识(1)
很明显,CLS是CTS的一个子集,而且是最小的子集. - 张子阳 .NET框架基础知识(1) 参考资料: http://www.tracefact.net/CLR-and-Framework/DotN ...
- RabbitMQ基础知识
RabbitMQ基础知识 一.背景 RabbitMQ是一个由erlang开发的AMQP(Advanced Message Queue )的开源实现.AMQP 的出现其实也是应了广大人民群众的需求,虽然 ...
- Java基础知识(壹)
写在前面的话 这篇博客,是很早之前自己的学习Java基础知识的,所记录的内容,仅仅是当时学习的一个总结随笔.现在分享出来,希望能帮助大家,如有不足的,希望大家支出. 后续会继续分享基础知识手记.希望能 ...
- selenium自动化基础知识
什么是自动化测试? 自动化测试分为:功能自动化和性能自动化 功能自动化即使用计算机通过编码的方式来替代手工测试,完成一些重复性比较高的测试,解放测试人员的测试压力.同时,如果系统有不份模块更改后,只要 ...
- [SQL] SQL 基础知识梳理(一)- 数据库与 SQL
SQL 基础知识梳理(一)- 数据库与 SQL [博主]反骨仔 [原文地址]http://www.cnblogs.com/liqingwen/p/5902856.html 目录 What's 数据库 ...
- [SQL] SQL 基础知识梳理(二) - 查询基础
SQL 基础知识梳理(二) - 查询基础 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5904824.html 序 这是<SQL 基础知识梳理( ...
- [SQL] SQL 基础知识梳理(三) - 聚合和排序
SQL 基础知识梳理(三) - 聚合和排序 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5926689.html 序 这是<SQL 基础知识梳理 ...
- [SQL] SQL 基础知识梳理(四) - 数据更新
SQL 基础知识梳理(四) - 数据更新 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5929786.html 序 这是<SQL 基础知识梳理( ...
- [SQL] SQL 基础知识梳理(五) - 复杂查询
SQL 基础知识梳理(五) - 复杂查询 [博主]反骨仔 [原文]http://www.cnblogs.com/liqingwen/p/5939796.html 序 这是<SQL 基础知识梳理( ...
随机推荐
- pycharm控制台中文乱码问题
pycharm控制台中文乱码问题一般是因为之前有配置保存到了文件里, C盘下.pycharm文件夹下有配置文件,删除文件后重装pycharm,配置会重置 不过最后解决问题的做法是删除配置文件后,重新装 ...
- MongoDB (十一) MongoDB 排序文档
sort() 方法 要在 MongoDB 中的文档进行排序,需要使用sort()方法. sort() 方法接受一个文档,其中包含的字段列表连同他们的排序顺序.要指定排序顺序1和-1. 1用于升序排列, ...
- lintcode:逆序对
题目 在数组中的两个数字如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对.给你一个数组,求出这个数组中逆序对的总数.概括:如果a[i] > a[j] 且 i < j, a[i] ...
- 本地替换文件读取MYSQL密码
Mysql 的密码默认是存储在/data/mysql/下面的三个文件中:user.MYD,user.frm,user.MYI 先把这三个文件下载到本地,然后替换本地的这三个文件 使用net stop ...
- python xml.etree ElementTree解析 编辑 xml
python有很多种xml解析方式,不过感觉etree的ElementTree 用起来最方便. #coding=utf-8 from xml.etree import ElementTree impo ...
- sql查询字段值的换行及回车符
SQL的换行.回车符,在MySQL.SQL Server和Oracle中均有不同,下面以列表显示. MySQL SQL Server Oracle 换行符 \n或\r\n或CHAR(10) CHA ...
- PHP代码优化技巧大盘点
PHP优化的目的是花最少的代价换来最快的运行速度与最容易维护的代码.本文给大家提供全面的优化技巧. 1.echo比print快. 2.使用echo的多重参数代替字符串连接. 3.在执行for循环之前确 ...
- ava中拦截器 过滤器 监听器都有什么区别
过滤器,是在java web中,你传入的request,response提前过滤掉一些信息,或者提前设置一些参数,然后再传入servlet或者struts2的action进行业务逻辑,比如过滤掉非法u ...
- makefile中的自动化变量 【转】
转自:http://blog.chinaunix.net/uid-28458801-id-3495215.html 自动化变量 模式规则中,规则的目标和依赖文件名代表了一类文件名:规则的命令是对所有这 ...
- svn版本库包含多个项目 ; git svn clone; 某一个子项目,有多个分支;
情况描述: 公司的svn版本库,包含了多个项目,每个项目对应于1个文件夹 假设版本库名字为Main,其下的项目用 A项目,对应文件夹A B项目,对应文件夹B 通过git svn clone获取了svn ...