我正在尝试使用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)从关键点创建矢量,然后尝试填充点矢量点列表的矢量。然后在调用flow funciton时将其转换为MatOfPoint2f (MatOfPoint2f)pointList (3)尝试从头开始填充MatOfPoint2f。无法弄清楚如何做到这一点 (4)在MatOfPoint2f中使用fromArray方法 - 不确定这个方法的作用。此方法的文档为空白。我错过了一些明显的东西吗?
答案 0 :(得分:0)
回答我自己的问题......我在另一个论坛得到了答案。该讨论的链接如下 http://www.answers.opencv.org/question/6206/opencv4android-conversion-from-matofkeypoint-to/