1. 程式人生 > >Halcon的編程語法與數據處理——第8講

Halcon的編程語法與數據處理——第8講

mod net dice bre elements sce .com 字符 endif

1、跟其他語言不完全一致的表達符號

賦值符號 :=

引號 ‘ ‘ (一律是單引號)

求商求余 / % (一個整數除以另一個數,如何使商是實型的?即浮點型)

邏輯運算 and or not xor(異或)

邏輯真假 true false

等於 = 和 == 都行

不等於 != 和 # 都行

2、程序控制語法

程序語法與Delphi、VB.Net極為類似。例如:

① for循環

for i := 1 to 10 by 1

……

endfor

② if/else判斷

if(……)

……

elseif(……)

……

else

……

endif

③ while循環

while(……)

……

endwhile

break、continue跟其他編程語言一致。

3、常見的Tuple函數運算

min(t) tuple中的最小值

max(t) tuple中的最大值

min2(t1,t2) 求兩個值(tuple)中的較小值

max2(t1,t2) 求兩個值(tuple)中的較大值

sum(t) 求和

mean(a) 求均值

deviation(a) 標準差( https://www.cnblogs.com/xh6300/p/7413715.html )

sqrt(a) 平方根

deg(a) 將弧度轉為角度

rad(a)

將角度轉為弧度

real(a) 將整型轉為real型

int(a) 將real型轉為整型

round(a) 轉換為最接近的整數元組

number(v) 將string類型轉為number類型

abs(a) 求絕對值

sort(t) 升序排列

更多Tuple的操作請參考:

https://www.cnblogs.com/xh6300/p/6117688.html

可以將下面的例子運行一下,感受一下:

技術分享圖片

 1 read_image (Image, code.png)
 2 create_bar_code_model ([], [], BarCodeHandle)
 3 dev_set_draw (margin)
 4 **同時查找Code 128碼和Code 39碼,這種方式消耗的時間只等於只找一種碼的時間。
 5 **得到的字符串元組str等於 [123456, 220519140360]
 6 find_bar_code (Image, SymbolRegions, BarCodeHandle, [Code 128,Code 39], str)
 7 
 8 num := |str|
 9 tuple_strlen (str, Length)  //獲得字符串元組中每個字符串的長度,[6,12]
10 
11 A0 := Length[0]    //等於6
12 
13 A1 := Length[1]    //等於12
14 
15 AA := A0 + A1      //等於18
16 
17 B0 :=str[0]        //得到的仍是一個字符串,‘123456‘
18 
19 B0_int :=number(str[0])  //貌似沒有字符串轉int類型,不過可以轉成number類型,123456
20 
21 aa := 3 + B0_int   //轉為數字可以進行四則運算了,123456 + 3 = 123459
22 
23 i :=[590,6]        //這裏創建的是一個整型元組
24 
25 i0 := i[0]         //等於590
26 
27 *數據轉字符串
28 aa := 590 + ‘‘

技術分享圖片

4、四舍五入、取整、有效數字以及和字符串之間的轉換

https://www.cnblogs.com/xh6300/p/10027998.html

5、數據排序算子

tuple_sort — Sort the elements of a tuple in ascending order.

tuple_sort_index — Sort the elements of a tuple and return the indices of the sorted tuple.(對元組的元素進行(升序)排序,並返回排序後的元組的索引(相對於輸入的tuple)。)

https://www.cnblogs.com/xh6300/p/6417801.html

Halcon的編程語法與數據處理——第8講