halcon学习笔记——(3)HDevelop language(基本语句)
1、标准赋值
Ø assign(Input, Result) //编辑形式,永远都是输入在前,输出在后
1: assign(sin(x) + cos(y), u)
Ø Result := Input //代码形式
1: u := sin(x) + cos(y) //与之前的assign(sin(x) + cos(y), u)是等价的
2、元组插入赋值
Ø insert(Tuple, NewValue, Index, Tuple) //编辑形式
1: Tuple := [1,2,3,4,5,6,7,8,9]
2: insert(Tuple,0,3,Tuple)
Ø Tuple[Index] := NewValue //代码形式
1: Tuple := [1,2,3,4,5,6,7,8,9]
2: Tuple[3]:=0
例程:
1: read_image (Mreut, 'mreut') //读入图像
2: threshold (Mreut, Region, 190, 255) //阈值化,输出阈值在190-255的Regions
3: Areas := [] //定义数组Areas
4: for Radius := 1 to 50 by 1 //循环
5: dilation_circle (Region, RegionDilation, Radius) //利用半径为Radius的圆对Region进行膨胀运算,输出
6: //RegionDilation,输出形式仍然为Region。
7: area_center (RegionDilation, Area, Row, Column) //输出区域的面积和中心像素坐标
8: Areas[Radius-1] := Area //对数组Areas的第Radius-1个元素进行赋值
9: 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到i2的元素 | 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函数
1: tuple_old := gen_tuple_const(100,666) //创建一个具有100个元素的,每个元素都为666的数组
2: tuple_new := gen_tuple_const(|tuple_old|,4711) //创建一个和原来数据长度一样的,每个元素为4711的数组
(2)当数组中的元素不同时,需要用循环语句对数组中的每一个元素赋值
例如:
1: tuple := [] //创建空数组
2: for i := 1 to 100 by 1 //建立步长为1的循环
3: tuple := [tuple,i*i] //将i方的值赋给数组的第i个元素
4: endfor //循环结束
算术运算
Ø 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
逻辑操作符
Ø lnot 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 string