//! \example tutorial-detection-object-mbt2.cpp #include #include #include #include #include #include #include #include //Options #define IMATCHING // #define HYBRID_MATCHING // #define VAR_TRESH #ifdef HYBRID_MATCHING enum State { WAITING_FOR_INITIALIZATION, TRACKING, LOST, UNCERTAIN //=Tracking OK / Matching FAIL }; #endif #if (VISP_HAVE_OPENCV_VERSION >= 0x020400) void learn(const vpImage &I, vpMbGenericTracker &tracker, vpKeyPoint &keypoint_learning, int id) { //! [Keypoints reference detection] std::vector trainKeyPoints; double elapsedTime; keypoint_learning.detect(I, trainKeyPoints, elapsedTime); //! [Keypoints reference detection] //! [Keypoints selection on faces] std::vector polygons; std::vector > roisPt; std::pair, std::vector > > pair = tracker.getPolygonFaces(); polygons = pair.first; roisPt = pair.second; std::vector points3f; vpHomogeneousMatrix cMo; tracker.getPose(cMo); vpCameraParameters cam; tracker.getCameraParameters(cam); vpKeyPoint::compute3DForPointsInPolygons(cMo, cam, trainKeyPoints, polygons, roisPt, points3f); //! [Keypoints selection on faces] //! [Keypoints build reference] keypoint_learning.buildReference(I, trainKeyPoints, points3f, true, id); //! [Keypoints build reference] //! [Display reference keypoints] for (std::vector::const_iterator it = trainKeyPoints.begin(); it != trainKeyPoints.end(); ++it) { vpDisplay::displayCross(I, (int)it->pt.y, (int)it->pt.x, 4, vpColor::red); } //! [Display reference keypoints] } #endif #ifdef VAR_TRESH //Compute cummulative variance of a list of vector. double varVector(std::list< vpArray2D > vector_list) { //Attention aux vecteurs vides double var[3], mean[3]; //Compute means for (std::list< vpArray2D >::iterator it=vector_list.begin(); it != vector_list.end(); ++it) { if((*it).size()!=3) { std::cout<<"WARNING varVector : invalid array size"< >::iterator it=vector_list.begin(); it != vector_list.end(); ++it) { for(unsigned int j=0; j< 3; j++) { var[j]+=(*(*it)[j]-mean[j])*(*(*it)[j]-mean[j]); } } for(unsigned int j=0; j<3; j++) { var[j] /= vector_list.size(); } return var[0]+var[1]+var[2]; } #endif #ifdef HYBRID_MATCHING float computeConfidenceLevel(std::list states) { float res = 0; for (std::list::iterator it=states.begin(); it != states.end(); ++it) { switch(*it) { case TRACKING: res += 1; break; case UNCERTAIN: res += 0.5; break; case LOST: res -=1; case WAITING_FOR_INITIALIZATION: break; } } res = res/states.size(); return res; } #endif int main(int argc, char **argv) { #if (VISP_HAVE_OPENCV_VERSION >= 0x020400) //! [MBT code] try { std::string videoname = "book.mpeg"; for (int i = 0; i < argc; i++) { if (std::string(argv[i]) == "--name") videoname = std::string(argv[i + 1]); else if (std::string(argv[i]) == "--help") { std::cout << "\nUsage: " << argv[0] << " [--name