我想使用的OpenCV的Android(2.4.3 OpenCV的),我写一个程序来跟踪关键点。 我试图用FeatureDetector检测关键点,然后Video.calcOpticalFlowPyrLK跟踪它们。 有我难倒的问题是,FeatureDetector函数返回一个MatOfKeyPoint而calcOpticalFlowPyrLK需要MatOfPoint2f。
需要注意的是MatOfKeyPoint是从MatOfPoint不同(转换从MatOfPoint到MatOfPont2f是直截了当)。
这是我到目前为止的代码:
//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?
事情我已经尝试过失败迄今:(1)keypoints.convertTo()(2)创建从关键点的载体,然后试图填充点矢量pointList的载体。 然后调用流功能可按(MatOfPoint2f)pointList(3)尝试从头填充MatOfPoint2f当强制转换为MatOfPoint2f。 无法弄清楚如何做到这一点(4)使用fromArray方法MatOfPoint2f - 不知道这是什么方法呢。 文档是空白的这种方法。 我失去了一些东西明显?