countNonZero
boundingRect
reduce 计算投影值
Mat mRegionInv = 255 - mBinSrc(rcBound);
Mat mHorProj;
reduce(mRegionInv / 255, mHorProj, 1, CV_REDUCE_SUM, CV_32SC1);
int nTopInd = 0;
if ( 0 != mHorProj.at<int>(0, 0) )
{
while( nTopInd < mHorProj.rows && mHorProj.at<int>(nTopInd, 0) )
{
nTopInd ++;
}
}
findContours(matBin.clone(), contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
boundingRect
reduce 计算投影值
Mat mRegionInv = 255 - mBinSrc(rcBound);
Mat mHorProj;
reduce(mRegionInv / 255, mHorProj, 1, CV_REDUCE_SUM, CV_32SC1);
int nTopInd = 0;
if ( 0 != mHorProj.at<int>(0, 0) )
{
while( nTopInd < mHorProj.rows && mHorProj.at<int>(nTopInd, 0) )
{
nTopInd ++;
}
}
findContours(matBin.clone(), contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
Rect r = boundingRect(contours[i]);
//图像匹配
Mat mTemplGray = cv::imread(pTemplePage->templateDM.szImageName, 0);
Mat matSearchImage = mBin(rcSearchRegion);
Mat matResult;
cv::matchTemplate(matSearchImage, mTempl, matResult, CV_TM_SQDIFF_NORMED);
double dMinValue;
Point ptMinLoc;
cv::minMaxLoc(matResult, &dMinValue, NULL, &ptMinLoc, NULL);
contentOffset.x = ptMinLoc.x + rcSearchRegion.x - datumPoint.x;
contentOffset.y = ptMinLoc.y + rcSearchRegion.y - datumPoint.y;