//! set the root score of the detection void setScore(float confidence) { if (confidence_.size() == 0) confidence_.resize(1); confidence_[0] = confidence; }
//! add a part score to the candidate, parameterized by a bounding box and confidence value void addPart(cv::Rect r, float confidence) { parts_.push_back(r); confidence_.push_back(confidence); }
//! get the root score of the detection. Using for sorting float score(void) const { return (confidence_.size() > 0) ? confidence_[0] : -std::numeric_limits<double>::infinity(); }
void DynamicProgram<T>::argmin(Parts& parts, const vector2DMat& rootv, const vector2DMat& rooti, const vectorf scales, const vector4DMat& Ix, const vector4DMat& Iy, const vector4DMat& Ik, vectorCandidate& candidates) { // for each scale, and each component, traverse back down the tree to retrieve the part positions const unsigned int nscales = scales.size(); #ifdef _OPENMP #pragma omp parallel for #endif for (int n = 0; n < nscales; ++n) { T scale = scales[n]; for (unsigned int c = 0; c < parts.ncomponents(); ++c) { // get the scores and indices for this tree of parts const vector2DMat& Iknc = Ik[n][c]; const vector2DMat& Ixnc = Ix[n][c]; const vector2DMat& Iync = Iy[n][c]; const unsigned int nparts = parts.nparts(c); // threshold the root score Mat over_thresh = rootv[n][c] > thresh_; Mat rootmix = rooti[n][c]; vectorPoint inds; Math::find(over_thresh, inds); for (unsigned int i = 0; i < inds.size(); ++i) { Candidate candidate; candidate.setComponent(c); vectori xv(nparts); vectori yv(nparts); vectori mv(nparts); for (unsigned int p = 0; p < nparts; ++p) { ComponentPart part = parts.component(c, p); // calculate the child's points from the parent's points unsigned int x, y, m; if (part.isRoot()) { x = xv[0] = inds[i].x; y = yv[0] = inds[i].y; m = mv[0] = rootmix.at<int>(inds[i]); } else { int idx = part.parent().self(); x = xv[idx]; y = yv[idx]; m = mv[idx]; xv[p] = Ixnc[p][m].at<int>(y,x); yv[p] = Iync[p][m].at<int>(y,x); mv[p] = Iknc[p][m].at<int>(y,x); } // calculate the bounding rectangle and add it to the Candidate Point pone = Point(1,1); Point xy1 = (Point(xv[p],yv[p])-pone)*scale; Point xy2 = xy1 + Point(part.xsize(mv[p]), part.ysize(mv[p]))*scale - pone; if (part.isRoot()) candidate.addPart(Rect(xy1, xy2), rootv[n][c].at<T>(inds[i])); else candidate.addPart(Rect(xy1, xy2), 0.0); } #ifdef _OPENMP #pragma omp critical(addcandidate) #endif { candidates.push_back(candidate); } } } } }