当前位置:文档之家› Halcon学习(24)总结(一)

Halcon学习(24)总结(一)

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;在此基础上,进入ORClass-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等;其他语言(略)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 //Difference of two images or derivates with integer precision(??)int4 //两幅灰度图的频谱direction //图片边缘的梯度方向real //边缘提取及特定灰度值的轮廓complex //图片频率分布cyclic //Assigning one "gray" value to each color(??)vector_field //连续图形的光学流分布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Ø 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) left shiftØ rsh(i,i) right shiftØ i band i bit-wise andØ i bor i bit-wise orØ i bxor i bit-wise xorØ bnot i bit-wise complement字符串操作Ø v$s conversion to string //字符串的格式化,有很丰富的参数Ø v + v concatenation of strings and additionØ strchr(s,s) search character in stringØ strstr(s,s) search substringØ strrchr(s,s) search character in string (reverse)Ø strrstr(s,s) search substring (reverse)Ø strlen(s) length of stringØ s{i} selection of one characterØ s{i:i} selection of substringØ split(s,s) splitting to substrings比较操作符Ø t < t less thanØ t > t greater thanØ t <= t less or equalØ t >= t greater or equalØ t = t equalØ t # t not equal逻辑操作符Ø not l negationØ l and l logical ’and’Ø l or l logical ’or’Ø l xor l logical ’xor’数学函数Ø sin(a) sine of aØ cos(a) cosine of aØ tan(a) tangent of aØ asin(a) arc sine of a in the interval [-p/2, p/ 2], a Î [-1, 1]Ø acos(a) arc cosine a in the interval [-p/2, p/2], a Î [-1, 1]Ø atan(a) arc tangent a in the interval [-p/2, p/2], a Î [-1, 1]Ø atan2(a,b) arc tangent a/b in the interval [-p, p]Ø sinh(a) hyperbolic sine of aØ cosh(a) hyperbolic cosine of aØ tanh(a) hyperbolic tangent of aØ exp(a) exponential functionØ log(a) natural logarithm, a> 0Ø log10(a) decade logarithm, a> 0Ø pow(a1,a2) powerØ ldexp(a1,a2) a1 pow(2,a2)其他操作(统计、随机数、符号函数等)Ø min(t) minimum value of the tupleØ max(t) maximum value of the tupleØ min2(t1,t2) element-wise minimum of two tuplesØ max2(t1,t2) element-wise maximum of two tuplesØ find(t1,t2) indices of all occurrences of t1 within t2Ø rand(i) create random values from 0..1 (number specified by i)Ø sgn(a) element-wise sign of a tupleØ sum(t) sum of all elements or string concatenationØ cumul(t) cumulative histogram of a tupleØ mean(a) mean valueØ deviation(a) standard deviationØ sqrt(a) square root of aØ deg(a) convert radians to degreesØ rad(a) convert degrees to radiansØ real(a) convert integer to realØ int(a) convert a real to integerØ round(a) convert real to integerØ number(v) convert string to a numberØ is_number(v) test if value is a numberØ abs(a) absolute value of a (integer or real)Ø fabs(a) absolute value of a (always real)Ø ceil(a) smallest integer value not smaller than aØ floor(a) largest integer value not greater than aØ fmod(a1,a2) fractional part of a1/a2, with the same sign as a1Ø sort(t) sorting in increasing orderØ uniq(t) eliminate duplicates of neighboring values(typically used in combination with sort)Ø sort_index(t) return index instead of valuesØ median(t) Median value of a tuple (numbers)Ø select_rank(t,v) Select the element (number) with the given rankØ inverse(t) reverse the order of the valuesØ subset(t1,t2) selection from t1 by indices in t2Ø remove(t1,t2) Remove of values with the given indicesØ environment(s) value of an environment variableØ ord(a) ASCII number of a characterØ chr(a) convert an ASCII number to a characterØ ords(s) ASCII number of a tuple of stringsØ chrt(i) convert a tuple of integers into a string6、Halcon名称解释Ø Operator: A procedure of the HALCON library used in HDevelop or one of the language interf aces.Ø Procedure (of HDevelop): A subroutine defined for the use inside HDevelop.Ø Region: Result of a segmentation like threshold. In other systems called blob, area, binary imag e, or island. Implemented using runlength encoding.Ø XLD: Extended Line Description. Universal data structure used to handle contour based data. M ainly used in the context of subpixel precise measurement.Ø Domain: Part of the image which is used for processing. In other systems called ROI (region of interest).Ø Channel: One image matrix of a multi-spectral image. One example is the red channel of an RG B image.Ø Iconic data: Overall term for images, regions, and XLD data. In object oriented languages (C++ and COM) and in HDevelop iconic data is represented by a polymorphic data type. In object orien ted languages iconic data is also called iconic object.Ø Control data: All non iconic data. Examples are single values (integer, real, and string), coordina tes, arrays of values.Ø Tuple: an array of values where each element can be of a different type. One can have both icon ic and control tuples.Ø HALCON object: Synonym for Iconic object / dataØ Image acquisition interface: Interface between the frame grabber /camera driver (SDK) and the HALCON library. The Image acquisition interface is a DLL which is dynamically loaded when cal ling open_framegrabber.Ø Language interface: Software that enables the programmer to use the HALCON library in a giv en language (e.g., C++).Ø Extension Package: A mechanism that enables the user to fully integrate user-defined procedure s into the HALCON environment. The extension package concept gives full access to the internal data structures of HALCON.Ø License file: File “license.dat“ in the directory “license“. This file is used together with hardware components (dongle or Ethernet card) to check if a co rrect license is available.Ø Help files: Files in the directory “help“ which are used to get online information about all HALCON operators. This is extensively use d by HDevelop.Ø Shape-Based Matching: Finding of an object in an image based on a predefined model. The sha pe based matching uses features to quickly locate objects very precisely.Ø Variation Model: A method to do print checking by presenting multiple good patterns to the syst em. The variation model learns the normal variation a good pattern and based on this information can detect real defects.Ø Measure Tool: A set of operators to find the exact location of edges along lines or circular arcs. Other systems call the similar tool, e.g., caliper.Ø Accuracy: The deviation from the true valueØ Precision: The standard deviation of the measurement7、Halcon函数典型函数Ø Filtering (noise, smoothing, edge, bit, arithmetic, enhancement)Ø Segmentation (thresholding, topology, region growing, classification, comparison)Ø Region processingØ MorphologyØ Feature extractionØ Edge detectionØ Color processing and classificationØ OCR / OCVØ Bar code / data codeØ MeasurementØ RectificationØ Gray value matching8、Halcon HDevEngineHDevEngine允许用户在应用程序中直接调用Halcon程序(*.hdvp),适用范围包括C++、COM、.NET语言。

相关主题