<!-- lang: cpp --> double CalcSimilarity(IplImage* S,IplImage* T)
{ double r = 0.f; int width = T->width; int height = T->height;code
uchar* ptrS = NULL; uchar* ptrT = NULL; float a = 0,b = 0,c = 0; for(int i=0;i<height;i++) { ptrS = (uchar*)S->imageData+i*S->widthStep; ptrT = (uchar*)T->imageData+i*T->widthStep; for(int j=0;j<width;j++) { a += ptrS[j]*ptrS[j]; c += ptrT[j]*ptrT[j]; b += ptrS[j]*ptrT[j]; } } return b / (sqrt(a) * sqrt(c));
}it