当前位置:文档之家› HALCON学习笔记

HALCON学习笔记


4、Halcon 数据结构 两类参数:图形参数 Iconic (image, region, XLD) 与 控制参数 Control (string, integer, real, handle),在 Halcon 算子的参数中,依次为:输入图形参数、输出图形参数、输入控制参数、 输出控制参数;并且其输入参数不会被算子改变。 图形参数 Iconic: Images Multiple channels Arbitrary region of interest Multiple pixel types (byte, (u)int1/2/4, real, complex, direction, cyclic, vector_field) byte, uint2 int1, int2 int4 direction real complex cyclic vector_field //灰度图像的标准编码 //Difference of two images or derivates with integer precision (??) //两幅灰度图的频谱 //图片边缘的梯度方向 //边缘提取及特定灰度值的轮廓 //图片频率分布 //Assigning one "gray" value to each color(??) //连续图形的光学流分布

while ... endwhile repeat ... until
此外,也有关键字 break、continue、return、exit、stop 用来控制语句的执行; 赋值语句在 Halcon 中也被当作函数来使用: 标准赋值 assign(Expression, ResultVariable) //编辑形式,永远都是输入在前,输出在后 ResultVariable := Expression //代码形式 元组插入赋值 insert(Tuple, NewValue, Index, Tuple) //编辑形式 Tuple[Index] := NewValue //代码形式 控制变量元组操作 [t,t] concatenation of tuples |t| number of elements t[i] selection of an element t[i:j] selection of a part of a tuple subset(t1,t2) selection from t1 by indices in t2 图形元组操作对应函数 [] gen_empty_obj () |t| count_obj (p, num) [t1,t2] concat_obj (p1, p2, q) t[i] select_obj (p, q, i+1) t[i:j] copy_obj (p, q, i+1, j-i+1) subset(t1,t2) select_obj (p, q, t2+1) 元组的数学运算,如:A * B,令 m = |A|, n = |B|; 若 m、n 不相等,且都大于 1,则错误;否则返回三种情况: m=n=1,返回一个值; m=n>1,返回一个包含 m 个数的元组,值为两元组各对于值的操作结果; m>1,n=1, 返回一个包含 m 个数的元组, 值为第二个数与第一元组各值的操作结果; Halcon 的数学运算 算术运算 a/a division a%a rest of the integer division a*a multiplication v+v addition and concatenation of strings a-a subtraction -a negation 位运算 lsh(i,i) rsh(i,i) i band i i bor i i bxor i bnot i left shift right shift bit-wise and bit-wise or bit-wise xor bit-wise complement

字符串操作

v$s v+v strchr(s,s) strstr(s,s) strrchr(s,s) strrstr(s,s) strlen(s) s{i} s{i:i} split(s,s)
conversion to string //字符串的格式化,有很丰富的参数 concatenation of strings and addition search character in string search substring search character in string (reverse) search substring (reverse) length of string selection of one character selection of substring splitting to substrings less than greater than less or equal greater or equal equal not equal negation logical ’and’ logical ’or’ logical ’xor’ sine of a cosine of a tangent of a arc sine of a in the interval [-/2, / 2], a [-1, 1] arc cosine a in the interval [-/2, /2], a [-1, 1] arc tangent a in the interval [-/2, /2], a [-1, 1] arc tangent a/b in the interval [-, ] hyperbolic sine of a hyperbolic cosine of a hyperbolic tangent of a exponential function natural logarithm, a> 0 decade logarithm, a> 0 power a1 pow(2,a2)
Regions Efficient data structure (runlength encoding) Extensive set of operators Fastest morphology on the market 图形编码中,需要了解 row 和 run 两个术语;也是 Halcon Region 存储的方式 Extended Line Description (XLD) Subpixel accurate line and edge detection Generic point list based data structure Handling of contours, polygons, lines, parallels, etc. 此外,Halcon 支持的类型还包括图形元组、控制变量元组及句柄: 元组的概念,使得可以用一个变量传递数个对象,可以由重载后的函数来进行处理;图形元 组的下标从 1 开始,控制变量元组下标从 0 开始;句柄则可以用来描述窗体、文件等等,句 柄不能是常量。 5、Halcon 语言 输入控制参数可以是表达式,但图形参数、输出参数均应为变量; String 类型变量由单引号 ’ 括起来;此外还有一些特殊字符; Boolean 型变量包括 true ( = 1 )、 false ( = 0 ) ;不为零的整数将被认为 true;但绝大多数的 Halcon 函数接受字符串型的表达:’true’ ‘false’,而非逻辑型表达; 函数返回常量用于标识错误: H_MSG_TRUE no error 2 H_MSG_FALSE logical false 3 H_MSG_FAIL operator did not succeed 5 可以放在 try…catch…endtry 块中,也可以用 dev_error_var() 与 dev_set_check() 来捕获; 控制语句结构: (与一般语言略有不同,它们也有输入输出变量) if ... endif / if ... else ... endif / if ... elseif ... else ... endif for ... endfor
Halcon 学习笔记 1、Halcon 的自我描述 Program Logic Each program consists of a sequence of HALCON operators The program can be structured into procedures The sequence can be extended by using control operators like if, for, repeat, or while The results of the operators are passed via variables No implicit data passing is applied Input parameters of operators can be variables or expressions Output parameters are always variables HDevelop has no features to design a graphical user interface An HDevelop program is considered as a prototypic solution of the vision part of an application HDevelop is typically not used for the final application 由此可以看出,Halcon 的定位是一个类库,有着完整、快速实现函数,同时提供了 HDevelop 作为快速开发的图形化(IDE)界面;但是,Halcon 程序并不是一个完整的最终应用软件, 它没有用户界面,也不提供显示的数据(公用的数据格式) 。 Halcon 的初学者也应当从参考 Halcon 的程序入手,熟悉 Halcon 类库,也即 HDevelop-Based Programming;在此基础上,进入 OR Class-Oriented Programming。这也是 Halcon 推荐的开 发方式: The vision part is solved with HDevelop, and the application is developed with C++ or Visual Basic。 2、HDevelop 界面的学习 通过阅读 Halcon 的 PPT,学到了下面一些有用的信息: 文件——浏览示例,可以看到很多有用的例子; 程序窗体中,可以浏览与编辑 Procedues(过程) ,这个其实就是自定义函数咯~还 可以自己修改这些过程,并添加说明文档; F4——将函数语句注释掉;F3——激活; 本地过程(Local Procedue)与外部过程(Externel Procedue) 3、基本语法结构 Halcon 的语法结构 类似于 Pascal 与 Visual Basic,大部分的语句是 Halcon 提供的算子,此外也包含了少部分的 控制语句; 不允许单独声明变量; 提供自动的内存管理(初始化、析构及 OverWrite) ,但句柄则需要显示释放; C++(算子模式) 通过代码导出,以 C++为例,默认导出为算子型的语法结构,而非面向对象的;在此模式下, 全部函数声明为全局类型,数据类型只需要用 Hobject、HTuple 两类类型进行声明; C++(面向对象) 可以以面向对象的方式重写代码,也即利用类及类的成员函数; 在这种模式下,控制变量的类型仍未 HTuple,而图形数据可以由多种类型,如 HImage 等; 其他语言(略)
相关主题