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)
顯示結果為:[1, 2, 3,0, 5, 6, 7, 8, 9]

Ø Tuple[Index] := NewValue                         //代碼形式

   1: Tuple := [1,2,3,4,5,6,7,8,9]
   2: Tuple[3]:=0
顯示結果為:[1, 2, 3,0, 5, 6, 7, 8, 9]

例程:

   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的數組
上面的函數也可以通過如下表達式實現:tuple_new := (tuple_old * 0) + 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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM