Ask Your Question
0

MultiTracker's trackers initialization for first frame

asked 2016-11-24 05:20:13 -0600

ManuVISION gravatar image

updated 2016-11-24 05:32:13 -0600

berak gravatar image

I followed the example mentioned in link of Opencv 3.1 How to initialize the trackers for the first frame ??? i mean in the example in the link they have used selectRoi for selection of objects befor the for loop. How to do the same with HOG SVM ??? someone plz help

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-11-24 05:55:25 -0600

berak gravatar image

the peopledetection gives you a vector<Rect> and you will have to translate that to a vector<Rect2d> for the multitracker:

// please use Ptr<MultiTracker>, not MultiTracker here, see below
Ptr<MultiTracker> trackers = makePtr<MultiTracker>(trackingAlg);

vector<Rect> v1; // from detection
vector<Rect2d> v2: // for tracking

for (size_t i=0; i<v1.size(); i++) {
    v2.push_back(v1[i]); //Rect2d has a constructor for Rect
}
trackers->add(frame, v2);

then you will have to check the return value from update():

bool ok = trackers->update(frame);
if (! ok) {
       // one of the trackers failed, now unfortunately, you will have to:
       // * create a new Multitracker instance with current image and current detections
       trackers = makePtr<MultiTracker>(trackingAlg);
       // * make a new peopledetection
       // * copy detections to tracking Rect2ds again, and 
       trackers->add(frame, objects);
}
edit flag offensive delete link more

Comments

thanks berak. Now how to draw rectangles around tracked objects ?? if I use the below for (unsigned i = 0; i < trackers.v2.size(); i++) { rectangle(img,trackers.v2[i], Scalar(255, 0, 0), 2, 1);}

the error show is MultiTracker has no member named v2. How to resolve this and draw rectangles around tracked objects ?? }

ManuVISION gravatar imageManuVISION ( 2017-01-06 03:38:51 -0600 )edit

(please look at the sample, again !)

bool ok = trackers->update(frame);
for(unsigned i=0;i<trackers.objects.size();i++)
  rectangle( frame, trackers.objects[i], Scalar( 255, 0, 0 ), 2, 1 );
berak gravatar imageberak ( 2017-01-06 04:07:35 -0600 )edit

Thanks for the reply. I did the same and every time it shows same error as Multitracker has no member objects.

If I check the cout<<ok <="" p="">

The output is always 1 means trackers are initialized.

Plz tell me where I am going wrong

ManuVISION gravatar imageManuVISION ( 2017-01-10 08:29:26 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-24 05:20:13 -0600

Seen: 898 times

Last updated: Nov 24 '16