比如说有两个图形都是圆,那么他们肯定相似,但是如何作出最快的判断啊?
解决方案 »
- 求大神指教怎么用MFC显示tiff图片
- 求助:使用BitBtl截屏时卡死
- windows shell扩展程序怎样与外部程序交互
- 树型控件,如何让每一项前面都有一个“+”号呢?
- 问一个关于new和delete的问题,100分相送,谢谢指教!
- 关于VC的单文档(SDI)类型的程序布局的问题?
- 一个UDP的问题,急!
- 怎么让CRichEditCtrl控件支持中文?因为有中文时它的LineIndex函数返回的值老是处错。
- 我做了一个CListCtrl控件,我想让List上填充两列数据,想让list的列宽固定,用户鼠标在列与列之间不能随时改变列的大小。 有没有办法?
- vs2008下 PreTranslateMessage不工作的问题
- MFC 写的ActiveX, 如何编译出它的proxy dll?
- static library里的资源如何应用到调用这个静态库的工程里?
BOOL WINAPI TemplateTimeDetect(LPSTR lpDIBBits,LPSTR lpTemplateDIBBits,LONG lWidth,LONG lHeight,LONG lTemplateWidth,LONG lTemplateHeight)
{ LPSTR lpSrc,lpTemplateSrc; //中间结果
double dSigmaST; //源图像和模板的关联性
double dSigmaS; //源图象的关联性
double dSigmaT; //模板的关联性
//相似性测度
double R;
//最大相似性测度
double MaxR;
//最大相似性出现位置
long lMaxWidth;
long lMaxHeight;
unsigned char pixel, templatepixel;
LONG lLineBytes=WIDTHBYTES(lWidth*8),lTemplateLineBytes=WIDTHBYTES(lTemplateWidth*8);
//计算dSigmaT
dSigmaT = 0;
for (LONG n = 0;n < lTemplateHeight ;n++)
{
for(LONG m = 0;m < lTemplateWidth ;m++)
{
// 指向模板图像倒数第j行,第i个象素的指针
lpTemplateSrc = (char *)lpTemplateDIBBits + lTemplateLineBytes * n + m;
templatepixel = (unsigned char)*lpTemplateSrc;
dSigmaT += (double)templatepixel*templatepixel;
}
} //在计算相似性时,不需要从图像第一行往下,因为得到是整体的值
MaxR = 0.0;
for (LONG j = 0;j < lHeight - lTemplateHeight +1 ;j++)
{
for(LONG i = 0;i < lWidth - lTemplateWidth + 1;i++)
{
dSigmaST = 0;
dSigmaS = 0;
for (LONG n = 0;n < lTemplateHeight ;n++)
{
for(LONG m = 0;m < lTemplateWidth ;m++)
{
// 指向源图像倒数第j+n行,第i+m个象素的指针
lpSrc = (char *)lpDIBBits + lLineBytes * (j+n) + (i+m);
// 指向模板图像倒数第n行,第m个象素的指针
lpTemplateSrc = (char *)lpTemplateDIBBits + lTemplateLineBytes * n + m;
pixel = (unsigned char)*lpSrc;
templatepixel = (unsigned char)*lpTemplateSrc;
dSigmaS += (double)pixel*pixel;
dSigmaST += (double)pixel*templatepixel;
}
}
//相关系数等于源图与模板象素的点乘(除以源图的点乘乘以模板的点乘)
R = dSigmaST / ( sqrt(dSigmaS)*sqrt(dSigmaT));
//与最大相似性比较
if (R > MaxR)
{
MaxR = R;
lMaxWidth = i;
lMaxHeight = j;
}
}
}// CString result;
// result.Format("Max Cof= %f",MaxR);
// AfxMessageBox(result); //将图像其余部分置黑,使匹配的那一部分能够更好的呈现
for (LONG i=0;i<lHeight;i++)
for (LONG j=0;j<lWidth;j++)
{
lpSrc = (char *)lpDIBBits + lLineBytes * i + j;
if (i>=lMaxHeight && i<lMaxHeight+lTemplateHeight && j>=lMaxWidth && j<lMaxWidth+lTemplateWidth)
{
pixel=(unsigned char)(*lpSrc);
pixel=(pixel<226?pixel+30:pixel);
*lpSrc=pixel;
}
else
{
pixel=(unsigned char)(*lpSrc);
pixel=(pixel>100?pixel-100:pixel);
*lpSrc=pixel;
}
} return TRUE;
}