您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > Halcon编程语法
输入控制参数可以是表达式,但图形参数、输出参数均应为变量;String类型变量由单引号’括起来;此外还有一些特殊字符;Boolean型变量包括true(=1)、false(=0);不为零的整数将被认为true;但绝大多数的Halcon函数接受字符串型的表达:’true’‘false’,而非逻辑型表达;函数返回常量用于标识错误:ØH_MSG_TRUEnoerror2ØH_MSG_FALSElogicalfalse3ØH_MSG_FAILoperatordidnotsucceed5可以放在try…catch…endtry块中,也可以用dev_error_var()与dev_set_check()来捕获;控制语句结构:(与一般语言略有不同,它们也有输入输出变量)Øif...endif/if...else...endif/if...elseif...else...endifØfor...endforØwhile...endwhileØrepeat...until此外,也有关键字break、continue、return、exit、stop用来控制语句的执行;赋值语句在Halcon中也被当作函数来使用:标准赋值Øassign(Expression,ResultVariable)//编辑形式,永远都是输入在前,输出在后ØResultVariable:=Expression//代码形式元组插入赋值Øinsert(Tuple,NewValue,Index,Tuple)//编辑形式ØTuple[Index]:=NewValue//代码形式控制变量元组操作Ø[t,t]concatenationoftuples元组链接Ø|t|numberofelements元素个数Øtselectionofanelement选择一个元素Øt[i:j]selectionofapartofatuple选择元组的一部分Øsubset(t1,t2)selectionfromt1byindicesint2图形元组操作对应函数Ø[]gen_empty_obj()Ø|t|count_obj(p,num)Ø[t1,t2]concat_obj(p1,p2,q)Øtselect_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|;若m、n不相等,且都大于1,则错误;否则返回三种情况:Øm=n=1,返回一个值;Øm=n1,返回一个包含m个数的元组,值为两元组各对于值的操作结果;Øm1,n=1,返回一个包含m个数的元组,值为第二个数与第一元组各值的操作结果;Halcon的数学运算算术运算Øa/adivisionØa%arestoftheintegerdivisionØa*amultiplicationØv+vadditionandconcatenationofstringsØa-asubtractionØ-anegation位运算Ølsh(i,i)leftshiftØrsh(i,i)rightshiftØibandibit-wiseandØiboribit-wiseorØibxoribit-wisexorØbnotibit-wisecomplement字符串操作Øv$sconversiontostring//字符串的格式化,有很丰富的参数Øv+vconcatenationofstringsandadditionØstrchr(s,s)searchcharacterinstringØstrstr(s,s)searchsubstringØstrrchr(s,s)searchcharacterinstring(reverse)Østrrstr(s,s)searchsubstring(reverse)Østrlen(s)lengthofstringØs{i}selectionofonecharacterØs{i:i}selectionofsubstringØsplit(s,s)splittingtosubstrings比较操作符ØttlessthanØttgreaterthanØt=tlessorequalØt=tgreaterorequalØt=tequalØt#tnotequal逻辑操作符ØnotlnegationØlandllogical’and’Ølorllogical’or’Ølxorllogical’xor’数学函数Øsin(a)sineofaØcos(a)cosineofaØtan(a)tangentofaØasin(a)arcsineofaintheinterval[-p/2,p/2],aÎ[-1,1]Øacos(a)arccosineaintheinterval[-p/2,p/2],aÎ[-1,1]Øatan(a)arctangentaintheinterval[-p/2,p/2],aÎ[-1,1]Øatan2(a,b)arctangenta/bintheinterval[-p,p]Øsinh(a)hyperbolicsineofaØcosh(a)hyperboliccosineofaØtanh(a)hyperbolictangentofaØexp(a)exponentialfunctionØlog(a)naturallogarithm,a0Ølog10(a)decadelogarithm,a0Øpow(a1,a2)powerØldexp(a1,a2)a1pow(2,a2)其他操作(统计、随机数、符号函数等)Ømin(t)minimumvalueofthetupleØmax(t)maximumvalueofthetupleØmin2(t1,t2)element-wiseminimumoftwotuplesØmax2(t1,t2)element-wisemaximumoftwotuplesØfind(t1,t2)indicesofalloccurrencesoft1withint2Ørand(i)createrandomvaluesfrom0..1(numberspecifiedbyi)Øsgn(a)element-wisesignofatupleØsum(t)sumofallelementsorstringconcatenationØcumul(t)cumulativehistogramofatupleØmean(a)meanvalueØdeviation(a)standarddeviationØsqrt(a)squarerootofaØdeg(a)convertradianstodegreesØrad(a)convertdegreestoradiansØreal(a)convertintegertorealØint(a)convertarealtointegerØround(a)convertrealtointeger四舍五入Ønumber(v)convertstringtoanumberØis_number(v)testifvalueisanumberØabs(a)absolutevalueofa(integerorreal)Øfabs(a)absolutevalueofa(alwaysreal)Øceil(a)smallestintegervaluenotsmallerthanaØfloor(a)largestintegervaluenotgreaterthanaØfmod(a1,a2)fractionalpartofa1/a2,withthesamesignasa1Øsort(t)sortinginincreasingorderØuniq(t)eliminateduplicatesofneighboringvalues(typicallyusedincombinationwithsort)Øsort_index(t)returnindexinsteadofvaluesØmedian(t)Medianvalueofatuple(numbers)Øselect_rank(t,v)Selecttheelement(number)withthegivenrankØinverse(t)reversetheorderofthevaluesØsubset(t1,t2)selectionfromt1byindicesint2Øremove(t1,t2)RemoveofvalueswiththegivenindicesØenvironment(s)valueofanenvironmentvariableØord(a)ASCIInumberofacharacterØchr(a)convertanASCIInumbertoacharacterØords(s)ASCIInumberofatupleofstringsØchrt(i)convertatupleofintegersintoastring
本文标题:Halcon编程语法
链接地址:https://www.777doc.com/doc-2875762 .html