getIndexFromLabel
opened this issue · comments
this returns an error on OS X 10.10 with OF 0.8.4
int temp_index = tracker.getIndexFromLabel(i);
Tracker.h:277:28: No member named 'getIndex' in 'cv::Rect_'
i am working of the ofxCv example-contours-following.
i think i just fixed this in develop, please test.
still see this problem. index is always -1
contourFinder.getTracker().getIndexFromLabel(labelsSorted[0]);
while this contourFinder.getLabel(0) returns good values
as further prove i added this line to the example-contours-tracking.
ofLog()<<i<<" label "<<label<<" labelB "<<contourFinder.getTracker().getLabelFromIndex(i)<<" index "<<contourFinder.getTracker().getIndexFromLabel(label);
i am using the develop branch
i found a hack i think.
if i make index public here: https://github.com/kylemcdonald/ofxCv/blob/master/libs/ofxCv/include/ofxCv/Tracker.h#L60
and add this line current.back().index = index;
here
https://github.com/kylemcdonald/ofxCv/blob/master/libs/ofxCv/include/ofxCv/Tracker.h#L201
and
https://github.com/kylemcdonald/ofxCv/blob/master/libs/ofxCv/include/ofxCv/Tracker.h#L213
For me its also not working.
After your hack (@stephanschulz) the function is returning values, but not the correct ones. Although the values lie within a reasonable range (always within the total number of detected contours) and there are no duplicate indices..
Any ideas @kylemcdonald , @stephanschulz ?
Seeing the same issues myself. Did you guys find a fix, @stephanschulz @tobiaszimmer ?
Building on @stephanschulz's approach, I added a setter for index
(instead of making it public) and then set it explicitly each time the object is pushed back onto current
. That seems to fix it. Looks like maybe the initializer isn't handling index
properly. I'll give it another look and submit a pull request.
Actually I think I just misunderstood what getLabelFromIndex
was for. It returns the index in the current
vector, not the index in the TrackerFollower
's followers
vector, which is what we want. But there's a labels
vector in TrackerFollower
that maps to followers
.
So I'm now looking up my label here instead of getLabelFromIndex
and it's working:
ofApp.h
ofxCv::RectTrackerFollower<Letter> letterTracker;
ofApp.cpp
vector<unsigned int> letterTrackerLabels = letterTracker.track(contourFinder.getBoundingRects());
vector<Letter>& letters = letterTracker.getFollowers();
const vector<unsigned int>& newLabels = letterTracker.getNewLabels();
// Find the Letter for any new Labels and set their image
for(int i = 0; i < newLabels.size(); i++) {
int newLabel = newLabels[i];
// Find position of Letter with that Label
vector<unsigned int>::const_iterator index = find(letterTrackerLabels.begin(), letterTrackerLabels.end(), newLabel);
if (index != letterTrackerLabels.end()) {
int iteratorPosition = distance<vector<unsigned int>::const_iterator> (letterTrackerLabels.begin(), index);
// If iteratorPosition is inside letters, then update image
if (iteratorPosition >= 0 && iteratorPosition < letters.size()) {
letters[iteratorPosition].callMyFunctionHere();
}
}
}