1. 程式人生 > >Halcon運算子(總結的很全面)

Halcon運算子(總結的很全面)

      

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

此外,也有關鍵字 breakcontinuereturnexitstop 用來控制語句的執行;

賦值語句在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|

mn不相等,且都大於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 string