zoukankan      html  css  js  c++  java
  • HALCON基础知识

    HALCON

    1. 语法范式 Syntax Style 

    1.1. 基本格式

    1.1.1. 算子格式

    算子(输入图像参数:输出图像参数:输入控制参数:输出控制参数)

    其中四个参数任意一个可以为空

    e.g.1.threshold(Image Region MinGrayMaxGray : ) 

    ** 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 : : : PointerTypeWidthHeight) 

    ** threshold算子,1 Image Para input : Image ; 2 Image Para output :

    **  3 Control Para input : 无 4 Control Para output : PointerTypeWidthHeight

    1.1.2. 程序结构

    HDEVHALCON Develop,相当于VCslnsolutiondev下面有很多窗口。

    dev_update_pc

    Switches the update of the PC during program execution on or off.

    dev_update_time

    Switch time measurement for operators on or off.

    dev_update_var

    Switches the update of the variable window during program execution on or off.

    dev_update_window

    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_

    gen_  gen系列跨度很大,一般属于Creation范畴,生成的可以是图像image,匹配模板model,区域region,轮廓Contour,亚像素级轮廓Contour XLD,滤波器filterHALCON内部描述文件descr(如标定板的表述caltab10mm.descr)等。下面展示的是一些容易混淆的gen_circle等,都是生成区域,属于Table of Contents/Regions/Creation

    gen_circle

    Create a circle.

    gen_ellipse

    Create an ellipse.

    gen_rectangle2

    Create a rectangle of any orientation.

    以画圆为例,含有RowColR,且这些都是输入量:

    gen_circle( : Circle RowColumnRadius : ) 

    draw_ 属于Table of Contents/Graphics/Drawing和我们平常理解的不同,这里的draw是指交互式地在窗口上画图,而不是直接按参数画图

    draw_circle

    Interactive drawing of a circle.

    draw_ellipse

    Interactive drawing of an ellipse.

    draw_line

    Draw a line.

    以画圆为例,虽然也有RowColR,但这些都是输出量:

    draw_circle( : : WindowHandle RowColumnRadius) 

    disp_ 属于Table of Contents/Graphics/Output

    disp_arc

    Displays circular arcs in a window.输出显示一段弧

    disp_arrow

    Displays arrows in a window.输出显示一个箭头

    disp_circle

    Displays circles in a window.

    disp_cross

    Displays crosses in a window.

    以画弧为例,虽然也有CRowCCol,而且这些都是输入的控制参数:

    disp_arc( : : WindowHandleCenterRowCenterColAngleBeginRowBeginCol : ) 

    2. 数据结构 Data Structure

    2.1. Tuple元组

    HALCON中的元组是一个涵盖范围很广的数据结构,可以表示各种整形浮点,也可以表示字符串。

    2.1.1. tuple的函数

    ① Tuple的长度

    tuple_length( : : Tuple Length) 

    e.g.tuple_length( RowsEdges, LengthEdge),还有一种更简单的方法,

    ② Tupleindex取元素

    tuple_select( : : TupleIndex Selected) 

    e.g.tuple_select( RowsEdges, 0,RowSelectedPoint)

    tuple_select_range( : : TupleLeftindexRightindex Selected) 

     Select several elements of a tuple between the left index and the right index.

    ③ Tuple的初始化,包含分配内存需要的长度以及初始值

    tuple_gen_const

    gen_tuple_const(NumHoles,0)

    2.1.2. tuple的操作符

    tuple的操作除了调用函数,还可以直接访问元素,或者使用操作符

    ① Tuple的长度

    Length:= |Tuple|

    e.g.LengthEdge1 := |RowsEdges| 

    ② Tupleindex取元素

    e.g.RowSelectedPoint := RowsEdges[0]

    2.2. 常见图像变量数据结构及相互转换

    ImageRegion, Contour ,XLD,几何图形

    2.2.1. Image  Region

    ① Image  Region

     threshold(Image Region MinGrayMaxGray : )

    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(ImageRegion ImageReduced : : ) 

    Reduce the domain of an image.提取ROI中的图像部分

    region_to_bin(Region BinImage ForegroundGrayBackgroundGrayWidthHeight : ) 

    Convert a region into a binary byte-image。将区域转化为二值图

    region_to_label(Region ImageLabel TypeWidthHeight : ) Convert regions to a label image.

    region_to_mean(RegionsImage ImageMean : : ) 

     Paint regions with their average gray value.  结合原图Image将区域内所有像素点转换为它的中值。

    2.2.2. Region  Contour 

    ① Region  Contour 

     

    gen_circle_contour_xld

    Create XLD contours corresponding to circles or circular arcs.

    gen_contour_nurbs_xld

    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).

    gen_contour_polygon_xld

    Generate an XLD contour from a polygon (given as tuples).

    gen_contour_region_xld

    Generate XLD contours from regions.

    gen_contours_skeleton_xld

    Convert a skeleton into XLD contours.

    gen_cross_contour_xld

    Generate one XLD contour in the shape of a cross for each input point.

    gen_ellipse_contour_xld

    Creation of an XLD contour corresponding to an elliptic arc.

    gen_nurbs_interp

    Create control data of a NURBS curve that interpolates given points.

    gen_parallels_xld

    Extract parallel XLD polygons.

    gen_polygons_xld

    Approximate XLD contours by polygons.

    gen_rectangle2_contour_xld

    Create an XLD contour in the shape of a rectangle.

    mod_parallels_xld

    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 FilterAlphaLowHigh : ) 

    主要介绍Canny边缘检测,同hysteresis_thresholdCanny边缘检测时不是单个阈值,而是有个“迟滞效应”设置了双阈值。

    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.

     

     





  • 相关阅读:
    nginx 配置优化(简单)
    Nginx 安装
    Smokeping安装教程
    test [ ] 四类
    if语句中的判断条件(nginx)
    力扣 1431. 拥有最多糖果的孩子 python
    力扣 1672. 最富有客户的资产总量+1512. 好数对的数目 python
    力扣 剑指 Offer 58
    力扣 8. 字符串转换整数 (atoi)python--每日一题
    力扣 7. 整数反转python 每日一题
  • 原文地址:https://www.cnblogs.com/ouxiaogu/p/3319600.html
Copyright © 2011-2022 走看看