Multiple tracking of people detected is not working. How to use MultiTracker??

asked 2017-04-12 14:46:55 -0500

ManuVISION gravatar image

I dont understand how to use the MultiTracker class in Opencv. I followed the example in MultiTracker documentation of OpenCV 3.2

Its not able to track at all.

Here is the code :

vector<rect> found, found_filtered;

        hog.detectMultiScale(img, found, 0, Size(4,4), Size(8,8), 1.05, 2);

        // Avoid non maxima supression

        size_t i, j;
        for (i = 0; i < found.size(); i++)
        {
            Rect r = found[i];
            for (j = 0; j < found.size(); j++)
                if (j != i && (r & found[j]) == r)
                    break;
            if (j == found.size())
                found_filtered.push_back(r);
        }

        // Draw Rectangles around detected objects in green
        for (i = 0; i < found_filtered.size(); i++)
        {
            Rect r = found_filtered[i];
            r.x += cvRound(r.width*0.1);
            r.width = cvRound(r.width*0.8);
            r.y += cvRound(r.height*0.06);
            r.height = cvRound(r.height*0.9);
            rectangle(img, r.tl(), r.br(), cv::Scalar(0, 255, 0), 2);
        } 

        vector<Rect2d> v2, objects; // for tracking

        for (size_t i = 0; i<found_filtered.size(); i++) {
            objects.push_back(found_filtered[i]); //Rect2d has a constructor for Rect . Convert Rect to Rect 2d
        }



        cout <<  v2.size() << endl;

                     MultiTracker trackers("KCF");

                     // initialize the tracker
                      trackers.add(img,objects);


                     //update the tracking result
                      trackers.update(img);


                      // draw the tracked object
                     for(unsigned i=0;i<trackers.objects.size();i++)
                     rectangle(img, trackers.objects[i], Scalar( 255, 0, 0 ), 2, 1 );

         imshow("Plotted", img);

        int key6 = waitKey(40);
    }
edit retag flag offensive close merge delete