从MatOfKeyPoint到MatOfPoint2f的OpenCV4Android转换 [英] OpenCV4Android conversion from MatOfKeyPoint to MatOfPoint2f

查看:201
本文介绍了从MatOfKeyPoint到MatOfPoint2f的OpenCV4Android转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将OpenCV用于Android(OpenCV 2.4.3) 我正在编写一个程序来跟踪关键点.我正在尝试使用FeatureDetector检测关键点,然后使用Video.calcOpticalFlowPyrLK 追踪他们. 让我感到困惑的问题是,FeatureDetector函数返回MatOfKeyPoint,而CalcOpticalFlowPyrLK则使用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.

请注意,MatOfKeyPoint与MatOfPoint不同(从MatOfPoint到MatOfPont2f的转换非常简单).

Note that MatOfKeyPoint is different from MatOfPoint (Conversion from MatOfPoint to MatOfPont2f is straightforward).

到目前为止,这是我的代码:

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?

到目前为止,我尝试失败的内容: (1)keypoints.convertTo() (2)从关键点创建向量,然后尝试填充Point Vector pointList的向量.然后在调用流函数时类型转换为MatOfPoint2f (MatOfPoint2f)pointList (3)尝试从头开始填充MatOfPoint2f.无法弄清楚如何做到这一点 (4)在MatOfPoint2f中使用fromArray方法-不确定此方法的作用.该方法的文档为空白.我缺少明显的东西吗?

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?

推荐答案

回答我自己的问题...我在另一个论坛中得到了答案.该讨论的链接如下 http://www.answers.opencv.org/问题/6206/opencv4android-conversion-from-matofkeypoint-to/

Answering my own question... I got the answer in another forum. The link to that discussion is below http://www.answers.opencv.org/question/6206/opencv4android-conversion-from-matofkeypoint-to/

这篇关于从MatOfKeyPoint到MatOfPoint2f的OpenCV4Android转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆