kylemcdonald / ofxCv

Alternative approach to interfacing with OpenCv from openFrameworks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

setFeatures / getFeatures logic for FlowPyrLK

ofZach opened this issue · comments

I am seeing an issue where when I set features before calling flow and read the features back they are the same. I can see that the features are actually changing when I trace it out:


            for (int i = 0; i < prevPts.size(); i++){
                cout << " prevPts " << i << " " << prevPts[i].x << " " << prevPts[i].y << endl;
            }
            
#if CV_MAJOR_VERSION>=2 && (CV_MINOR_VERSION>4 || (CV_MINOR_VERSION==4 && CV_SUBMINOR_VERSION>=1))
			if (prevPyramid.empty()) {
				buildOpticalFlowPyramid(prev,prevPyramid,cv::Size(windowSize, windowSize),10);
			}
			buildOpticalFlowPyramid(next,pyramid,cv::Size(windowSize, windowSize),10);
			calcOpticalFlowPyrLK(prevPyramid,
                                 pyramid,
                                 prevPts,
                                 nextPts,
                                 status,
                                 err,
                                 cv::Size(windowSize, windowSize),
                                 maxLevel);
			prevPyramid = pyramid;
			pyramid.clear();
            
            for (int i = 0; i < nextPts.size(); i++){
                cout << " nextPts " << i << " " << nextPts[i].x << " " << nextPts[i].y << endl;
            }

you see things like:

 prevPts 0 870 976
 prevPts 1 990 1100
 nextPts 0 870.315 976.232
 nextPts 1 983.649 1096.83

I feel like the error is here:

	vector<ofPoint> FlowPyrLK::getFeatures(){
		ofPolyline poly =toOf(prevPts);
		return poly.getVertices();
	}

where it should be returning nextPts (which are changed after flow calculation not before) but I'm not 100% sure I understand the swapping logic to know if this change would have some other bad side effects.

I guess "getCurrent" would give back the right results, but what is the difference between getCurrent() and getFeatures() ? maybe the api is a little unclear here? I suspected from naming I could use setFeatures(), calcFlow() then getFeatures()....

@obviousjim wrote this part of ofxCv he might be able to provide some clarification