QQ登录

只需一步,快速开始

工业视觉halcon tuple相关函数详解

[ 复制链接 ]
前面帖子有分享了tuple部分相关函数的介绍,
函数分类有很多,
每个分类下,函数有多有少,
为方便统一学习,这里将剩余的全部tuple相关函数列出,
可以运行实践部分的代码,查看每个函数的功能与效果。

1.halcon tuple属性相关函数详解
Tuple属性相关函数有
tuple_length
tuple_min
tuple_max
tuple_sum
tuple_mean
tuple_median
tuple_deviation
tuple_histo_range
可用于计算数组元素个数,最大,最小,平均值等
下面的代码可以在halcon中运行,
查看每个函数执行效果。
test1:=[1,2,3,4,5,6,7]
tuple_length (test1, Length)
tuple_min (test1, Min)
tuple_max (test1, Max)
tuple_sum (test1, Sum)
tuple_mean (test1, Mean)
tuple_median (test1, Median)
tuple_deviation (test1, Deviation)
tuple_histo_range (test1, 0, 10, 5, Histo, BinSize)

2.halcon tuple算术相关函数详解
Halcon中,Tuple算术相关的函数有很多,有些很常用,有些不常用,
有些要有一些基础才能够理解,
实际中我们熟悉一些常用算术函数便可。
tuple_fabs   tuple_abs   tuple_add   tuple_sub   tuple_mult   tuple_div   tuple_fmod   tuple_mod    tuple_pow  tuple_sqrt  tuple_floor  tuple_ceil  tuple_sgn  tuple_deg  tuple_rad  tuple_neg
tuple_max2  tuple_min2  tuple_exp  tuple_ldexp
tuple_log  tuple_log10  tuple_cumul   tuple_vector_cross_product
tuple_cos
tuple_acos
tuple_cosh
tuple_sin
tuple_asin
tuple_sinh
tuple_tan
tuple_atan
tuple_atan2
tuple_tanh
下边的代码可以在halcon中执行,
查看每个函数的运行效果。
a:=-1
b:=[4,5,6]
c:=[2,3,4]
tuple_fabs (-12.34, Abs1)
tuple_abs (a, Abs)
tuple_add (1, 1, Sum)
tuple_sub (b, c, Diff)
tuple_mult (2, 2, Prod)
tuple_div (4, 2, Quot)
*取余
tuple_fmod (5.1, 2, Fmod)
tuple_mod (3, 2, Mod)
*乘方
tuple_pow (2, 3, Pow)
*开方
tuple_sqrt (9, Sqrt)
*下取整
tuple_floor (4.9, Floor)
*上取整
tuple_ceil (4.1, Ceil)
*取符号
d:=[-1,3,-6]
tuple_sgn (d, Sgn)
e:=[1,2,3,4]
*tuple_cumul (e, Cumul)
*弧度转角度
tuple_deg (3.1415926, Deg)
*角度转弧度
tuple_rad (45, Rad)
*正负符号取反
tuple_neg (-12.1, Neg)
*两元组元素成对对比,取大/小值,元组长度需相同,或一元组长度为1
f:=[1,2,3,4]
g:=[1,3,4,5]
tuple_max2 (f, g, Max2)
tuple_min2 (f, 4, Min2)
*计算指数,2.71828*的(参数1)次方
tuple_exp (2, Exp)
*计算公式:T1*2^{T2}即4*2^3=32
tuple_ldexp (4, 3, Ldexp)
*求自然对数:以e=2.71828为底,参数1的对数,即2.71828的Log次方等于7.38905
tuple_log (7.38905, Log)
*求以10为底,参数一的对数,即10的Log1次方等于100
tuple_log10 (100, Log1)
*累积和计算:f=[1,2,3,4]. 1;1+2=3;1+2+3=6;1+2+3+4=10; 结果[1,3,6,10]
tuple_cumul (f, Cumul)
*计算3元素长度向量的交叉乘积
h:=[1,2,3]
g:=[4,5,6]
tuple_vector_cross_product (h, g, VC)
*余弦,反余弦,双曲余弦函数计算
tuple_cos (rad(60), Cos)
tuple_acos (0.5, ACos)
degree:=deg(ACos)
tuple_cosh (Cos, Cosh)
*正弦,反正弦,双曲正弦函数计算
tuple_sin (rad(30), Sin)
tuple_asin (Sin, ASin)
degree:=deg(ASin)
tuple_sinh (Sin, Sinh)
*正切,余切,双曲正切函数计算
tuple_tan (rad(40), Tan)
tuple_atan (1.0, ATan)
degree:=deg(ATan)
*下面算子等于tuple_atan(0.57735/1,ATan)
tuple_atan2 (0.57735,1, ATan1)
degree:=deg(ATan1)
tuple_tanh (Tan, Tanh)

3.halcon tuple修改相关函数详解
Tuple元组内的元素,还可以进行更改,添加,删除操作,
halcon提供以下几个函数完成
tuple_insert
tuple_remove
tuple_replace
也可以运行下面每个函数,
查看效果。
a:=[1,2,3,4,5]
b:=[99,88]
tuple_insert (a, 0, b, Extended)
tuple_remove (Extended, [0,3], Reduced)
tuple_replace (a, 0, 77, Replaced)

4.halcon tuple选择相关函数详解
Tuple元组内的元素,还支持按一定的规则进行选择操作。比如剔除元组内连续相同的元素,将指定范围内的元素选择出来等等。
Halcon提供以下几个函数来选择元素
tuple_find
tuple_find_first
tuple_find_last
tuple_first_n
tuple_last_n
tuple_select
tuple_select_range
tuple_select_rank
tuple_str_bit_select
tuple_uniq
tuple_select_mask
可以运行下边代码,查看每个函数运行效果。
a:=[1,2,3,4,5,6,7,2,3]
b:=[2,3]
tuple_find (a, b, Indices)
tuple_find_first (a, b, Index)
tuple_find_last (a, b, Index1)
tuple_first_n (a, 1, Selected)
tuple_last_n (a, 1, Selected1)
tuple_select (a, 2, Selected2)
tuple_select_range (a, 1, 3, Selected4)
c:=[5,4,3,2,1]
tuple_select_rank (c, 2, Selected3)
d:=['12','34','56']
tuple_str_bit_select (d, 1, Selected5)
e:=[1,2,3,3,3,4,4,4,5,5,5]
tuple_uniq (e, Uniq)
tuple_select_mask (a,[1,0,1,1,1,1,1,1,0], Selected3)

5. halcon tuple元素排序相关函数详解
元组内部元素可以按照升序或降序进行排列,也可以将元素排列任意打乱等等操作,halcon中也有针对元素排序的函数,这些函数为
tuple_inverse
tuple_sort
tuple_sort_index
tuple_shuffle
可以运行下边的代码,
查看每个函数的运行结果。
a:=[1,2,3,5,4]
tuple_inverse (a, Inverted)
tuple_sort (Inverted, Sorted)
tuple_sort_index (a, Indices)
tuple_shuffle (a, Shuffled)

6.halcon tuple转换相关函数详解
Tuple元组中,元素有整形的,浮点型的,字符型的,字符串型的,这些类型的元素都可以用halcon提供的几个函数实现相互转换
共有10个函数
tuple_chr
tuple_ord
tuple_chrt
tuple_ords
tuple_string
tuple_number
tuple_is_number
tuple_int
tuple_real
tuple_round
也可以可halcon编程软件中运行下边的代码,
查看 每个函数运行的结果。
a:= 0x30
tuple_chr (a, Chr)
tuple_ords ('z', Ords)
b := [0x30,0x31]
tuple_chrt (b, Chrt)
tuple_ords ('ab', Ords1)
tuple_number ('0XF', Number)
tuple_string (123.0, '.3f', String)
tuple_is_number ('9', IsNumber)
tuple_ord ('3', Ord)
tuple_int (1, Int)
tuple_real (12, Real)
tuple_round (12.4, Round)

7.halcon tuple字符串操作相关函数详解
Halcon提供针对字符串操作的相关函数,
可以对字符串内字符进行搜索,替换,截取,也支持正则表达式。
正则表达式的使用要事先熟悉其语法。
Halcon手册内也有提供语法的介绍。
这些对字符串的操作函数有:
tuple_strlen
tuple_str_first_n
tuple_str_last_n
tuple_split
tuple_strchr
tuple_strrchr
tuple_strstr
tuple_strrstr
tuple_substr
tuple_evironment
tuple_regexp_match
tuple_regexp_replace
tuple_regexp_select
tuple_regexp_test
可以运行下边的代码,
查看 每个函数执行的结果。
a := 'gkbc8.com'
*计算字符串长度
tuple_strlen (a, Length)
tuple_str_first_n (a, 4, Substring) *取0到指定索引全部字符串
tuple_str_last_n (a, 5, Substring1) *取指定索引到结尾全部字符串
tuple_split (a, '.', Substrings) *用字符串中的字符分割字符串
tuple_strchr (a, '8', Position) *正向查找字符,返回第一个找到的字符索引,无返回-1
tuple_strrchr (Substrings, Substrings, Position1) *反向查找字符,返回第一个找到字符的索引
tuple_strstr (a, 'con', Position2) *正向查找字符串,返回第一个找到的字符索引,无返回-1
tuple_strrstr (a, 'com', Position3) *反向查找字符串,返回第一个找到字符的索引
tuple_substr (a, 0, 4, Substring2) *提取指定范围的字符串
tuple_environment ('HALCONEXAMPLES', Values) *读取环境变量值例如:HALCONEXAMPLES
*正则表达式操作字符串
tuple_regexp_match (a, 'com', Matches)
tuple_regexp_replace (a, 'com', 'cn', Result)
b:=['gkbc8.com','baidu.com']
tuple_regexp_select (b, 'c8', Selection)
tuple_regexp_test ('p10662599755', '[A-Z]*', NumMatches)

当前帖子为下边halcon视频教程的部分内容,
可以下载教程学习与实践。
  

halcon从自学到接项目视频教程,另外再赠送全网最全资源  

  

欢迎围观我录制的一套halcon自学视频教程(进入)


  

上位机VC MFC程序开发精典实例大全源码与视频讲解配套下载408例

  

经历1年的编程与录制点击进入查看


  

如果您认可,可联系功能定制!

  

如果您着急,充值会员可直接联系发您资料!

  

QQ联系我

微信扫扫联系我

  



回复

使用道具 举报

点击查看
快速回复 返回列表 客服中心 搜索