Halcon中循环的相关算子

条件<condition> ,<condition> 内为计算成an integer or boolean value的表达式。六.Halcon控制循环算子

表达式的值1则条件为真,否则为假。

1.if(<condition>)。。。 endif:条件为真时,执行条件后的内容,否则转到endif.

2.if (<condition>)...else...endif:条件为真,执行if...else部分,否则执行else...endif,典型的选择条件语句。

3.elseif相当于算子2的else部分,但是它允许测试一个附件条件。

例如:if (<condition1>)...elseif (<condition2>)...endif 当条件1为假条件2为真时,执行条件2后面的部分。在语法结构上等价于:if (<condition1>)
                               ...
                          else
                          if (<condition2>)
                            ...
                          endif
                        endif

循环控制语句

1.while (<condition>)... endwhile:循环控制结构,当条件为真时,执行循环体。可以利用operator continuebreak操作来重新开始或立刻终止循环。

2.repeat...until (<condition>):循环体至少被执行一次,直到满足条件时退出。

3.for <index> := <start> to <end> by <step>...endfor

halcon最重要的循环结构,呵呵不细说了~同样,可以利用operator continuebreak操作来重新开始或立刻终止循环。

例如:

old_x := 0
old_y := 0
dev_set_color ('red')
dev_set_part(0, 0, 511, 511)
for x := 1 to 511 by 1
y := sin(x / 511.0 * 2 * 3.1416 * 3) * 255
disp_line (WindowID, -old_y+256, old_x, -y+256, x)
old_x := x
old_y := y
endfor

4.continue:强制执行下一个循环。

例如:i := |Images|
while (i)
Image := Images[i]
count_channels (Image, Channels)
if (Channels # 3)
continue
endif
* extensive processing of color image follows
endwhile

5.break:强制退出循环。

例1.

Number := |Regions|
AllRegionsValid := 1
* check whether all regions have an area <= 30
for i := 1 to Number by 1
ObjectSelected := Regions[i]
area_center (ObjectSelected, Area, Row, Column)
if (Area > 30)
AllRegionsValid := 0
break ()
endif
endfor

例2.

while (1)
grab_image (Image, FGHandle)
dev_error_var (Error, 1)
dev_set_check ('~give_error')
get_mposition (WindowHandle, R, C, Button)
dev_error_var (Error, 0)
dev_set_check ('give_error')
if ((Error = H_MSG_TRUE) and (Button # 0))
break ()
endif
endwhile

其他

1.stop:终止后面的循环,点击Step Over or Run button继续。

2.exit:终止Hdevelop程序段。

3.return:从当前的程序返回到正在呼叫的算子。

4.try ... catch ... endtry:异常算子处理句柄

5.throw:允许处理用户定义的意外情况。

猜你喜欢

转载自www.cnblogs.com/6-6-8-8/p/9549582.html