欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > 1. halcon基础语言语法

1. halcon基础语言语法

2025/6/20 20:21:52 来源:https://blog.csdn.net/2301_80188818/article/details/148765019  浏览:    关键词:1. halcon基础语言语法

目录

1. 注释

2. 数据类型

1. 图像变量

2. 控制变量

3. 变量的使用

  1. 在halcon

2. 在c#

4. 运算符

 1. 算数运算符

2. 关系运算符

3. 逻辑运算符

5. 选择结构

6. 快捷键

7. 循环结构

8. 数组(集合)

9. 数组集合运算

10. 字符串算子

11. 文件

12.冒泡排序


1. 注释

  1. 符号*

  2. F4 批量注释 F3取消注释

  3. if(false)

2. 数据类型

1. 图像变量

  1. 图像 image

  2. 区域 region

  3. 轮廓 xld

2. 控制变量

 1. 基础数据类型

 2. 字符串 ''

3. 变量的使用

  1. 在halcon

 1. 不需要定义

  2. 没有数据类型, 自动判断该数据的类型

 3. 不需要分号结束

  4. 赋值 :=

    data1 := 10data2 := 3.14data3 := 'hello world'data4 := false

2. 在c#

 1. 区别

4. 运算符

 1. 算数运算符

     + - * / %

    data1 := 10data2 := 20data3 := data1 + data2data4 := data1 - data2data5 := data1 * data2data6 := data1 / data2data7 := data1 % data2

2. 关系运算符

  1.> >= < <= = !=(#)

 2. 逻辑真(true/1)假(false/0)

    data1 := 10data2 := 10data3 := data1 > data2//data1大于data2是假,所以data3等于0data4 := data1 >= data2data5 := data1 < data2data6 := data1 <= data2data7 := data1 = data2//data1等于data2是真,所以data7等于1data8 := data1 != data2data9 := data1 # data2

3. 逻辑运算符

 1. and 

 2. or

3. not

    data1 := 1data2 := 0data3 := data1 and data2//逻辑与(两个为真才为真)data4 := data1 or data2 //逻辑或(有一个真就是真)data5 := not data1//逻辑非(真转假)

5. 选择结构

1. if

 2. if else

3. if elseif elseif

 4. switch case 

   data1 := 1data2 := 0if (data1)endifif (data1)elseendifif (data1)elseif(data2)endifswitch (data1)case 1:breakcase 2:breakcase 3:breakdefault:breakendswitch

6. 快捷键

tab tab enter

7. 循环结构

1. while

2. for

  data1 := 0while (data1 < 100)data1 := data1 + 10 endwhiledata2 := 1rst := 0for Index := 1 to 5 by 1//to是小于等于,前面是i=1,从1 开始,后面是1++rst := data2 * Indexendforfor Index1 := 1 to 5 by 1if (Index1 = 2)continue//结束本次循环break//结束本次循环endifendforfor Index2 := 1 to 5 by 1for Index3 := 1 to 5 by 1for Index4 := 1 to 5 by 1endforendforendfor

8. 数组(集合)

 *数组arry := []//定义一个数组arry1 := [1,2,3]//数组有三个数据arry2 := ['hello','hi','ok']data1 := arry1[0]//下标法,取第0个数据,data1=1*集合arry1 := [arry1,10]//在arry1的后面加10arry1 := [20,arry1]//在arry1的前面面加20rows := []cols := []for Index := 1 to 5 by 1a :=  arry1[Index-1]  //五个数据,下标应该是四rows := [rows, Index]//往rows里面循环添加数据cols := [cols, Index*2]//往cols里面循环添加数据endfor

9. 数组集合运算

1. tuple_

    Arry := [1,3,5,7,9,2,4,6,8,10,8,4,2,1]//数组里面存的tuple_min (Arry, Min)//从Arry里面查找并且输出最小值 tuple_max (Arry, Max)//从Arry里面查找并且输出最大值tuple_mean (Arry, Mean)//从Arry里面计算并且输出平均值tuple_median (Arry, Median)//从Arry里面查找并且输出中间值tuple_sort (Arry, Sorted)//从Arry里面查找并且输出排序(从小到大)tuple_uniq (Sorted, Uniq)//从Arry里面查找并且删除掉重复的*查询tuple_find (Arry, 5, Indices)//从Arry里面查找5,如果找到,Indices会显示5的下标,如果没有会显示-1tuple_find (Arry, 1, Indices1)//如果查出两个同样的数字,会显示两个下标tuple_find_first (Arry, 1, Index)//查找第一个1的下标(从前往后找)tuple_find_last (Arry, 1, Index1)//查找第一个1的下标(从后往前找)tuple_length (Arry, Length)//查找数组有多少个下标 (第一种方法)  for Index2 := 1 to Length by 1endforLen := |Arry|//查找数组有多少个下标,|Arry|是数组的长度 (第二种方法)  for Index3 := 1 to |Arry| by 1endfor*插入(增加)tuple_insert (Arry, 0, 100, Extended)//在Arry的第【0】个位置插入100tuple_insert (Arry, 1, [100,200], Extended1)//在Arry的第【1】个位置插入100,200*删除tuple_remove (Arry, 0, Reduced)//删除Arry的第【0】个数组*修改tuple_replace (Arry, 0, 30, Replaced)//在Arry把下标【0】删除,并且替换成30

10. 字符串算子

1. tuple_str_

 data1 := 1.2365678tuple_string (data1, '.2f', String)//把data1保留“.2f”计算保留小数点的后两位data2 := 'hello world'tuple_strlen (data2, Length)tuple_substr (data2, 6, 10, Substring)tuple_split (data2, ' ', Substrings)

11. 文件操作

打开文件,写入文本 
open_file ('lw.txt', 'append', FileHandle)fwrite_string (FileHandle, 'hallo1' + '\n')fwrite_string (FileHandle, '你好1' + '\n')close_file (FileHandle)
 读取文件中内容open_file ('lw.txt', 'input', FileHandle1)Lines := []IsEOF := 0while (IsEOF != 1)fread_string (FileHandle1, OutString, IsEOF)if (IsEOF)breakendifLines := [Lines, OutString]endwhileclose_file (FileHandle1)

12.冒泡排序

Arry := [1,3,5,7,9,2,4,6,8,10]MaxData := Arry[0]for Index := 1 to |Arry| by 1if (Arry[Index-1] > MaxData)MaxData := Arry[Index-1]endifendforfor Index1 := 1 to |Arry|-1 by 1for Index2 := 1 to |Arry|-1- Index1 by 1if (Arry[Index2-1] > Arry[Index2 + 1-1])Temp := Arry[Index2-1]Arry[Index2-1] := Arry[Index2 + 1 - 1]Arry[Index2 + 1 - 1] := Tempendifendforendfor

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词