vector具体的使用方式可以查看Halcon自带的vector_variables.hdev例程,这里我们主要介绍一下如何使用vector来简化函数的传参,达到c#中list等容器的效果。举例如下:
当我们有一个总的检测函数Inspect,该函数内部包含断路、短路、区域丢失、腐蚀残留、凸起缺损共五种缺陷检测函数,我们需要将所有种类的缺陷坐标传递出来,此时Inspect函数大致为如下形式:
Inspect(image,openRowCenter, openColCenter,shortRowCenter, shortColCenter,lossRowCenter, lossColCenter,residualRowCenter, residualColCenter,HNRowCenter, HNColCenter)
可见上述Inspect函数参数列表包含的参数很多,我们可以使用vector来简化参数列表,将其变为如下形式:
Inspect(image,FlawPoint)
具体实现方式如下:
1、在Inspect函数内部声明一个三维的vector变量FlawPoints,将每种缺陷的坐标添加到该变量中。输出该变量时注意要将其修改为三维的向量,如下图所示:
***断路检测
OpenDetect (RegionWait, openRowCenter, openColCenter)
***短路检测
ShortDetect (RegionWait,shortRowCenter, shortColCenter)
***区域丢失检测
LossDetect (RegionWait, lossRowCenter, lossColCenter)
***腐蚀残留检测
ResidualDetect ( RegionWait,residualRowCenter, residualColCenter)
***缺损、凸起检测
HumpAndNotchDetect (RegionWait,HNRowCenter, HNColCenter)
***使用三维向量存储缺陷坐标
FlawPoints:={ {{'断路'},{openRowCenter, openColCenter}}, \
{{'短路'},{shortRowCenter, shortColCenter}},\
{{'区域丢失'},{lossRowCenter, lossColCenter}}, \
{{'腐蚀残留'},{residualRowCenter, residualColCenter}},\
{{'缺损凸起'},{HNRowCenter, HNColCenter}}\
}
2、在Inspect函数外再次声明一个相同的三维vector变量FlawPoints,然后将传递出来的FlawPoint变量里的值循环添加到FlawPoints中
FlawPoints:={ {{'断路'},{[],[]}}, \
{{'短路'},{[],[]}},\
{{'区域丢失'},{[],[]}},\
{{'腐蚀残留'},{[],[]}},\
{{'缺损凸起'},{[],[]}}\
}
for Index := 1 to numObj by 1
select_obj (inspectModelBoundarys, ObjectSelected,Index)
reduce_domain (ImageAffineTrans, ObjectSelected, ImageReduced)
Inspect (ImageReduced, FlawPoint)
for Index1 := 0 to FlawPoints.length()-1 by 1
FlawPoints.at(Index1).at(1).at(0):=
[FlawPoints.at(Index1).at(1).at(0),FlawPoint.at(Index1).at(1).at(0)]
FlawPoints.at(Index1).at(1).at(1):=
[FlawPoints.at(Index1).at(1).at(1),FlawPoint.at(Index1).at(1).at(1)]
endfor
endfor