halcon 常用运算符

1.Assign算子:assign(Input, Result),对变量以及表达式或数组赋值

      assign(sin(x) + cos(y), u)
      which is displayed in the program window as:  程序窗等价为
      u := sin(x) + cos(y)

      Tuple1 := [1,0,3,4,5,6,7,8,9]    // 对数组进行初始化

      Val := sin(1.2) + cos(1.2)      // 对某一个值进行赋值

      Tuple2 := []              // 数组定义  

2.Insert : 对数组中的某一个值进行赋值。

      Tuple1 := [1,0,3,4,5,6,7,8,9]
      Tuple1[3]:=2

  显示结果为:[1, 0, 3, 2, 5, 6, 7, 8, 9],即对索引3后面元素,数组Tuple1中第4个元素赋值2.

example:

read_image (Mreut, 'mreut')                               //读入图像
threshold (Mreut, Region, 190, 255)                      //阈值化,输出阈值在190-255的Regions
Areas := []                                                  //定义数组Areas
for Radius := 1 to 50 by 1                                  //循环
dilation_circle (Region, RegionDilation, Radius)             //利用半径为Radius的圆对Region进行膨胀运算,输出

                                                   RegionDilation输出形式仍然为Region。
area_center (RegionDilation, Area, Row, Column)           //输出区域的面积和中心像素坐标
Areas[Radius-1] := Area                                      //对数组Areas的第Radius-1个元素进行赋值
endfor

3.基本数组操作极其对应的算子

t := [t1,t2]     t1,t2连接成新的数组                 对应算子:tuple_concat
i := |t|         得到数组长度                                  tuple_length
v := t[i]        选取第i个元素0<= i < |t|                     tuple_select
t := t[i1:i2]    选取i1到i1的元素                              tuple_select_range
t := subset(t,i) 选取数组t中的第i个元素                        tuple_select
t := remove(t,i) 去除数组t中的第i个元素                       tuple_remove
i := find(t1,t2) 找到t2数组在t1数组中出现位置索引

                  (or -1 if no match)                          tuple_find
t := uniq(t)     在t数组中把连续相同的值只保留一个             tuple_uniq

4.创建数组

(1)gen_tuple_const函数

  tuple := gen_tuple_const(100,4711) //创建一个具有100个元素的,每个元素都为4711的数据

  tuple_new := gen_tuple_const(|tuple_old|,4711) //创建一个和原来数据长度一样的数据

  上面的函数也可以通过如下表达式实现:tuple_new := (tuple_old * 0) + 4711

(2)当数组中的元素不同时,需要用循环语句对数组中的每一个元素赋值

  例如:tuple := []                                          //创建空数组
  for i := 1 to 100 by 1                                    //建立步长为1的循环
    tuple := [tuple,i*i]                                   //将i方的值赋给数组的第i个元素
  endfor                                                     //循环结束

http://blog.sina.com.cn/s/blog_442bfe0e0100yexg.html

原文地址:https://www.cnblogs.com/-liszt/p/5653798.html