Android OpenCV Detecting Circles takes too much FPS

时间:2015-06-15 14:18:43

标签: android opencv geometry

Currently I'm developing an app that'll detect circles in Camera View. So far I was able to write a code that succesfuly detects circles in Image. Now I have this code that does the same thing every frame:

 public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

    mat = inputFrame.rgba();
    grayMat = inputFrame.gray();    

        Imgproc.GaussianBlur(grayMat, grayMat, new Size(9, 9), 2, 2);
        Imgproc.HoughCircles(grayMat, circles,
                Imgproc.CV_HOUGH_GRADIENT, dp, minDist, param1,
                param2, minRadius, maxRadius);
        int numberOfCircles = (circles.rows() == 0) ? 0 : circles.cols();
        for (int i=0; i<numberOfCircles; i++) {
            double[] circleCoordinates = circles.get(0, i);
            int x = (int) circleCoordinates[0], y = (int) circleCoordinates[1];
        Point center = new Point(x, y);
            int radius = (int) circleCoordinates[2];           
            Core.circle(mat, center, radius, new Scalar(0,
                    255, 0), 4);      
            Core.rectangle(mat, new Point(x - 5, y - 5),
                    new Point(x + 5, y + 5),
                    new Scalar(0, 128, 255), -1);
        }   
        return mat;
}

It is detecting circles, but the problem is it takes too long. In fact when I call an empty onCameraFrame, that returns just rgba, I have 14+ fps, but when I use the complete code above fps drops drastically low. Maximum to 1 frame. And it shows a lot of false positives. How then a lot of apps can detect circles and even faces, without any fps drop? Thanks in advance.

1 个答案:

答案 0 :(得分:2)

我有同样的问题,我找到了这个http://android.phonesdevelopers.com/553_20483346/ 建议通过mOpenCvCameraView.setMaxFrameSize(640, 480);降低相机的分辨率。

我试了一下,画面以7/8 fps的速度增加;我认为这是一个开始。