I am trying to use OpenCV for Android (OpenCV 2.4.3) I am writing a program for tracking key points. I try to use FeatureDetector to detect key points, and then Video.calcOpticalFlowPyrLK track them. The question that puzzled me is that the FeatureDetector function returns MatOfKeyPoint, and calcOpticalFlowPyrLK accepts MatOfPoint2f.
Note that MatOfKeyPoint is different from MatOfPoint (converting from MatOfPoint to MatOfPont2f is simple).
Here is my code:
//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've tried so far unsuccessfully: (1) keypoints.convertTo () (2) Creating a vector from key points, and then trying to populate the PointList Point Point vector. Then cast to MatOfPoint2f when calling the funciton (MatOfPoint2f) function pointList (3) Trying to populate MatOfPoint2f from scratch. I canβt figure out how to do this (4) Using the fromArray method in MatOfPoint2f - You donβt know what this method does. The documentation for this method is empty. Am I missing something?
source share