功能:
从一堆轮廓中,选择最短轮廓和最长轮廓。
函数原型:
select_min_max_length_contour(Contours : MinLengthContour, MaxLengthContour : : )
函数体: - *打开错误信息
- dev_set_check('give_error')
- *最长轮廓变量初始化
- gen_empty_obj(MaxLengthContour)
- *开启捕获异常
- try
- *统计轮廓集合的数量
- count_obj(Contours, Number)
- *捕获异常
- catch(Exception)
- *异常处理
- return()
- endtry
- *如果轮廓数量无效,返回
- if(Number<1)
- return()
- endif
- *最长长度、最长长度索引初始化
- Max_Length:=0
- Max_Index:=0
- *遍历每个轮廓的长度
- for i:=1 to Number by 1
- *选择轮廓
- select_obj(Contours, ObjectSelected, i)
- *求轮廓长度
- length_xld(ObjectSelected, Length)
- *保存最长轮廓的长度和索引
- if(Max_Length<Length)
- Max_Length:=Length
- Max_Index:=i
- endif
- endfor
- *选择最长轮廓
- select_obj(Contours, MaxLengthContour, Max_Index)
- *返回
- return ()
复制代码
函数文件下载链接:
http://pan.baidu.com/s/1ntr1n9f
使用方法: 解压缩后,把文件《select_max_length_contour.hdvp》放置在halcon安装硬盘的路径 Program Files\MVTec\HALCON-10.0\procedures 关闭并重新启动HDevelop。
|