具体思路如下:首先,通过cvMatchTemplate模板进行匹配,匹配完成之后会产生一张结果单通道的灰色图像,再利用cvMinMaxLoc函数查找数组中全局最小值。每次最小值肯定只有一个,所以需要把每次找到的最小值(数组区域处理其它值,本文处理为最大值,也就是匹配最不像的值),这样就可以继续查找全局接剩余较小的区域了。
CvPoint getNextMinLoc(IplImage *result, CvPoint minLoc, int maxVaule, int templatW, int templatH)
{
// 先将第一个最小值点附近两倍模板宽度和高度的都设置为最大值防止产生干扰
int startX = minLoc.x - templatW;
int startY = minLoc.y - templatH;
int endX = minLoc.x + templatW;
int endY = minLoc.y + templatH;
if(startX < 0 || startY < 0)
{
startX = 0;
startY = 0;
}
if(endX > result->width - 1 || endY > result->height - 1)
{
endX = result->width - 1;
endY = result->height - 1;
}
for(int y = startY; y < endY; y++)
for