我正在尝试使用 OpenCV for Android (OpenCV 2.4.3) 我正在编写一个程序来跟踪关键点。我正在尝试使用 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)从关键点创建一个向量,然后尝试填充一个点向量点列表的向量。然后在调用流函数 (MatOfPoint2f) pointList (3) 尝试从头开始填充 MatOfPoint2f 时将类型转换为 MatOfPoint2f。无法弄清楚如何执行此操作 (4) 在 MatOfPoint2f 中使用 fromArray 方法 - 不确定此方法的作用。此方法的文档为空白。我错过了一些明显的东西吗?