2017-06-13 69 views
0

我想开发一个android应用程序,它应该分析从相机的帧和检测角落。Android OpenCV FAST角落检测过滤

我的目标是检测当前的棋盘状态并向服务器提供数据。

我在我的应用程序中实现了OpenCV,我试图使用FAST角点检测。

这是我分析当前的相机框架的我的代码部分:

@Override 
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) { 
    MatOfKeyPoint points = new MatOfKeyPoint(); 
    try { 
     Mat mat = inputFrame.rgba(); 
     FeatureDetector fast = FeatureDetector.create(FeatureDetector.FAST); 
     fast.detect(mat, points); 


     Scalar redcolor = new Scalar(255, 0, 0); 
     Mat mRgba = mat.clone(); 
     Imgproc.cvtColor(mat, mRgba, Imgproc.COLOR_RGBA2RGB, 4); 

     Features2d.drawKeypoints(mRgba, points, mRgba, redcolor, 1); 
     mat.release(); 
     return mRgba; 
    } 
    catch (Exception e) 
    { 
     return inputFrame.rgba(); 
    } 
} 

此代码的工作。问题是我得到太多的角落。我想知道一种实现阈值的方法。

在这Doc它谈到了“nonmaxsuppression”。

如果有人不知道答案,但知道在哪里可以找到android更新的文档,那就太棒了!

谢谢!

+0

你可能只是全部排序根据[回应]的关键点(http://docs.opencv.org/trunk/d2/ d29/classcv_1_1KeyPoint.html#a1f163ac418c281042e28895b20514360) –

+0

可以告诉我一些代码吗?我无法弄清楚如何得到这个“响应”参数 –

+0

刚刚添加了一个答案 –

回答

1

有两种方法,我知道的,你可以用它来排序的关键点:

  1. 更新探测器用不同的阈值.xml/.yml文件。你可以找到关于如何做到这一点here

  2. 您可以排序MatOfKeyPoint的反应和选择第一个100或200,只要你想参考。您可以使用以下Java中这样做:

    // Sort and select 500 best keypoints List<KeyPoint> listOfKeypoints = matrixOfKeypoints.toList(); Collections.sort(listOfKeypoints, new Comparator<KeyPoint>() { @Override public int compare(KeyPoint kp1, KeyPoint kp2) { // Sort them in descending order, so the best response KPs will come first return (int) (kp2.response - kp1.response); } }); List<KeyPoint> listOfBestKeypoints = listOfKeypoints.subList(0, 500);

+0

如何将listOfKeypoints转换为“MatOfKeyPoints”传递给“Features2d.drawKeypoints”参数? (第二种方式) –

+0

http://docs.opencv.org/java/2.4.9/org/opencv/utils/Converters.html#vector_vector_KeyPoint_to_Mat(java.util.List,java.util.List) –

+0

感谢:D。 .... –