Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV4Android conversion from MatOfKeyPoint to MatOfPoint2f

I am trying to use OpenCV for Android (OpenCV 2.4.3) I am writing a program to track keypoints. I am trying to use FeatureDetector to detect keypoints and then Video.calcOpticalFlowPyrLK to track them. The question that has me stumped is that the FeatureDetector function returns a MatOfKeyPoint while calcOpticalFlowPyrLK takes a MatOfPoint2f.

Here is my code so far:

//Feature detector for LKT flow estimation FeatureDetector cvFeatureDetector; //Vector of keypoints MatOfKeyPoint keypoints;

... ...

//intitialize detector cvFeatureDetector = FeatureDetector.create(FeatureDetector.GFTT);

keypoints = new MatOfKeyPoint();

... ...

//mPrevImgMat is a grayscale image - previous frame //mCurrentImgMat is a grayscale image - current frame

//Run feature detector in previous image cvFeatureDetector.detect(mPrevImgMat, keypoints);

MatOfPoint2f keypointsFound = new MatOfPoint2f(); MatOfByte keypointsStatus = new MatOfByte(); MatOfFloat err = new MatOfFloat(); Size winSize = new Size(25,25); int maxLevel = 3;

//Optical flow to find keypoints in current image Video.calcOpticalFlowPyrLK(mPrevImgMat, mCurrentImgMat, keypoints, keypointsFound, keypointsStatus, err, winSize, maxLevel);

//Obviously "keypoints" in the line above does not work. How does one covert //keypoints to MatOfPoint2f?

Things I have tried unsuccessfully so far: (1) keypoints.convertTo() (2) Creating a vector from keypoints and then trying to populate a vector of Point Vector pointList. Then typecast to MatOfPoint2f when calling flow funciton (MatOfPoint2f) pointList (3) Trying to populate a MatOfPoint2f from scratch. Cant figure out how to do this (4) Using fromArray method in MatOfPoint2f - Not sure what this method does. Documentation is blank for this method. Am I missing something obvious?

OpenCV4Android conversion from MatOfKeyPoint to MatOfPoint2f

I am trying to use OpenCV for Android (OpenCV 2.4.3) I am writing a program to track keypoints. I am trying to use FeatureDetector to detect keypoints and then Video.calcOpticalFlowPyrLK to track them. The question that has me stumped is that the FeatureDetector function returns a MatOfKeyPoint while calcOpticalFlowPyrLK takes a MatOfPoint2f.

Here is my code so far:

//Feature detector for LKT flow estimation
FeatureDetector cvFeatureDetector;
//Vector of keypoints
MatOfKeyPoint keypoints;

... ...

keypoints; ... ... //intitialize detector cvFeatureDetector = FeatureDetector.create(FeatureDetector.GFTT);

keypoints = new MatOfKeyPoint();

... ...

FeatureDetector.create(FeatureDetector.GFTT); keypoints = new MatOfKeyPoint(); ... ... //mPrevImgMat is a grayscale image - previous frame //mCurrentImgMat is a grayscale image - current frame

frame //Run feature detector in previous image cvFeatureDetector.detect(mPrevImgMat, keypoints);

keypoints); MatOfPoint2f keypointsFound = new MatOfPoint2f(); MatOfByte keypointsStatus = new MatOfByte(); MatOfFloat err = new MatOfFloat(); Size winSize = new Size(25,25); int maxLevel = 3;

3; //Optical flow to find keypoints in current image Video.calcOpticalFlowPyrLK(mPrevImgMat, mCurrentImgMat, keypoints, keypointsFound, keypointsStatus, err, winSize, maxLevel);

maxLevel); //Obviously "keypoints" in the line above does not work. How does one covert //keypoints to MatOfPoint2f?

MatOfPoint2f?

Things I have tried unsuccessfully so far: (1) keypoints.convertTo() (2) Creating a vector from keypoints and then trying to populate a vector of Point Vector pointList. Then typecast to MatOfPoint2f when calling flow funciton (MatOfPoint2f) pointList (3) Trying to populate a MatOfPoint2f from scratch. Cant figure out how to do this (4) Using fromArray method in MatOfPoint2f - Not sure what this method does. Documentation is blank for this method. Am I missing something obvious?

click to hide/show revision 3
formatting

OpenCV4Android conversion from MatOfKeyPoint to MatOfPoint2f

I am trying to use OpenCV for Android (OpenCV 2.4.3) I am writing a program to track keypoints. I am trying to use FeatureDetector to detect keypoints and then Video.calcOpticalFlowPyrLK to track them. The question that has me stumped is that the FeatureDetector function returns a MatOfKeyPoint while calcOpticalFlowPyrLK takes a MatOfPoint2f.

Here is my code so far:

//Feature detector for LKT flow estimation
FeatureDetector cvFeatureDetector;
 //Vector of keypoints
MatOfKeyPoint keypoints;
 ...
...

//intitialize detector
cvFeatureDetector = FeatureDetector.create(FeatureDetector.GFTT);

keypoints = new MatOfKeyPoint();
 ...
...

//mPrevImgMat is a grayscale image - previous frame
//mCurrentImgMat is a grayscale image - current frame

//Run feature detector in previous image
cvFeatureDetector.detect(mPrevImgMat, keypoints);

MatOfPoint2f keypointsFound = new MatOfPoint2f();
MatOfByte keypointsStatus = new MatOfByte();
MatOfFloat err = new MatOfFloat();
Size winSize = new Size(25,25);
int maxLevel = 3;

//Optical flow to find keypoints in current image
Video.calcOpticalFlowPyrLK(mPrevImgMat, mCurrentImgMat, keypoints,
            keypointsFound, keypointsStatus, err, winSize, maxLevel);

//Obviously "keypoints" in the line above does not work. How does one covert
//keypoints to MatOfPoint2f?

Things I have tried unsuccessfully so far: (1) keypoints.convertTo() (2) far:

  1. keypoints.convertTo()
  2. Creating a vector from keypoints and then then trying to populate a vector of Point Vector pointList. Then typecast to MatOfPoint2f to MatOfPoint2f when calling flow funciton (MatOfPoint2f) (MatOfPoint2f) pointList (3)
  3. Trying to populate a MatOfPoint2f MatOfPoint2f from scratch. Cant figure out how to to do this (4) 4 Using fromArray fromArray method in MatOfPoint2f MatOfPoint2f - Not sure what this this method does. Documentation is blank for this method. Am I missing missing something obvious?