gpt4 book ai didi

objective-c - cvMatchTemplate得分

转载 作者:行者123 更新时间:2023-12-02 17:54:57 24 4
gpt4 key购买 nike

我正在使用openCV的cvMatchTemplate方法在较大的图像中查找较小的图像。下面的\方法将现有的图案对象与给定的“当前”图像进行匹配,找到的图案由在当前图像上绘制的矩形标记。当模式可见时,它可靠地找到它;而当它的图形不在某个“随机”位置时,这是有意义的。

我在计算模板匹配的分数时遇到了麻烦。有容易确定的吗?我在各个站点上查找,但是找不到解决方案,也在查看cvMinMaxLoc计算出的值,但是找不到确定匹配质量的方法。

- (void)detect:(IplImage *)current
{
int patchx = pattern->width;
int patchy = pattern->height;
int iwidth = current->width - patchx + 1;
int iheight = current->height - patchy + 1;

IplImage *result=cvCreateImage( cvSize(iwidth,iheight),IPL_DEPTH_32F, 1);
cvMatchTemplate( current, pattern, result, CV_TM_SQDIFF );

CvPoint minloc, maxloc;
double minval, maxval;

cvMinMaxLoc( result, &minval, &maxval, &minloc, &maxloc, 0 );

/* draw red rectangle */
cvRectangle( current,
cvPoint( minloc.x, minloc.y ),
cvPoint( minloc.x + patchx, minloc.y + patchy ),
cvScalar( 0, 255, 0, 0 ), 1, 0, 0 );
}

最佳答案

使用标准化的度量标准(例如CV_TM_CCORR_NORMEDCV_TM_SQDIFF_NORMED),并将最小值与阈值(0到1.0之间)进行比较。

cvMatchTemplate( current, pattern, result, CV_TM_SQDIFF_NORMED);

if (minval < THRESHOLD) {
/* draw red rectangle */
cvRectangle( current,
cvPoint( minloc.x, minloc.y ),
cvPoint( minloc.x + patchx, minloc.y + patchy ),
cvScalar( 0, 255, 0, 0 ), 1, 0, 0 );
} else {
//not found
}

关于objective-c - cvMatchTemplate得分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8719579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com