int Detector::test(IntegralImage &intg, SubwinInfoT &subwin) { if (preTest(intg, subwin) == 0) { return 0; } double value = 0; int stage_count = 0; for (int i=0; i<ptr_model->weak_learner_num; i++) { double temp = ptr_model->p_weak_learners[i].test(intg, subwin); value += temp; if (i != ptr_model->stage_idx[stage_count]) { continue; } if (value < ptr_model->stage_thd[stage_count]) { return 0; } stage_count++; } return 1; }
bool Comb::calc(Point startPoint, Point endPoint, vector<Point>& combPoints) { if (shorterThen(endPoint - startPoint, MM2INT(1.5))) return true; bool addEndpoint = false; //Check if we are inside the comb boundaries if (!checkInside(startPoint)) { if (!moveInside(&startPoint)) //If we fail to move the point inside the comb boundary we need to retract. return false; combPoints.push_back(startPoint); } if (!checkInside(endPoint)) { if (!moveInside(&endPoint)) //If we fail to move the point inside the comb boundary we need to retract. return false; addEndpoint = true; } //Check if we are crossing any bounderies, and pre-calculate some values. if (!preTest(startPoint, endPoint)) { //We're not crossing any boundaries. So skip the comb generation. if (!addEndpoint && combPoints.size() == 0) //Only skip if we didn't move the start and end point. return true; } //Calculate the minimum and maximum positions where we cross the comb boundary calcMinMax(); int64_t x = sp.X; vector<Point> pointList; //Now walk trough the crossings, for every boundary we cross, find the initial cross point and the exit point. Then add all the points in between // to the pointList and continue with the next boundary we will cross, until there are no more boundaries to cross. // This gives a path from the start to finish curved around the holes that it encounters. while(true) { unsigned int n = getPolygonAbove(x); if (n == UINT_MAX) break; pointList.push_back(matrix.unapply(Point(minX[n] - MM2INT(0.2), sp.Y))); if ( (minIdx[n] - maxIdx[n] + boundery[n].size()) % boundery[n].size() > (maxIdx[n] - minIdx[n] + boundery[n].size()) % boundery[n].size()) { for(unsigned int i=minIdx[n]; i != maxIdx[n]; i = (i < boundery[n].size() - 1) ? (i + 1) : (0)) { pointList.push_back(getBounderyPointWithOffset(n, i)); } }else{ minIdx[n]--; if (minIdx[n] == UINT_MAX) minIdx[n] = boundery[n].size() - 1; maxIdx[n]--; if (maxIdx[n] == UINT_MAX) maxIdx[n] = boundery[n].size() - 1; for(unsigned int i=minIdx[n]; i != maxIdx[n]; i = (i > 0) ? (i - 1) : (boundery[n].size() - 1)) { pointList.push_back(getBounderyPointWithOffset(n, i)); } } pointList.push_back(matrix.unapply(Point(maxX[n] + MM2INT(0.2), sp.Y))); x = maxX[n]; } pointList.push_back(endPoint); //Optimize the pointList, skip each point we could already reach by not crossing a boundary. This smooths out the path and makes it skip any unneeded corners. Point p0 = startPoint; for(unsigned int n=1; n<pointList.size(); n++) { if (collisionTest(p0, pointList[n])) { if (collisionTest(p0, pointList[n-1])) return false; p0 = pointList[n-1]; combPoints.push_back(p0); } } if (addEndpoint) combPoints.push_back(endPoint); return true; }