// check ratio requirement b:w:b:w:b = 1:1:3:1:1
bool qr_checkRatio()
{
totalFinderSize = 0;
for(int i =0;i<5; i++)
{
int count = stateCount[i];
totalFinderSize += count;
if(count == 0)
return false;
}
if(totalFinderSize<7)
return false;
int moduleSize = ceil(totalFinderSize / 7.0); // scale factor of the finder
// tolerate some "slop" of the ratio
double maxVariance = moduleSize*tol_factor;
bool retVal = ((abs(moduleSize - (stateCount[0]))< maxVariance) &&
(abs(moduleSize - (stateCount[1]))< maxVariance) &&
(abs(3*moduleSize - (stateCount[2]))< 3*maxVariance) &&
(abs(moduleSize - (stateCount[3]))< maxVariance) &&
(abs(moduleSize - (stateCount[4]))< maxVariance));
return retVal;
}
以上代码就是判断是否为一个块。这个探测图像的比例为(1:1:3:1:1),计算出每个模块的平均宽度。差值不能超过0.5,这个tol_factor=0.5。如果满足这个条件那么就是我们所需找的一个定位点。
/* group possible finder locations, that is, each location vote in an array, so that
we can find three largest votes, calculate the mean location of these three groups and
finally draw them on the image
*/
void group_points(vector<Point>& points)
{
CvScalar red = CV_RGB(255,0,0);
/* if the size of vector, number of possible finder locations is greater than 3,
we need to group the