Android OpenCV提高检测质量

Ole*_*sov 6 java geometry android opencv

目前我正在开发一个应用程序,它将检测照片中的圆圈.我已经设法为此编写了一个代码,但如果我从PC屏幕稍微离开电话,它可能会出现漏报或误报.如何改进结果呢?我的意思是,有很多应用可以检测出小而不清楚的圆圈.

[更新]

我在摆弄值GaussianBlurHoughCircles.更改 Imgproc.GaussianBlur(grayMat, grayMat, new Size(9, 9), 2, 2);Imgproc.GaussianBlur(grayMat, grayMat, new Size(9, 9), 9, 9);param1 = 70, param2 = 72;double param1 = 50, param2 = 52;改善的结果,但还不够.

            Mat mat = new Mat(bitmap.getWidth(), bitmap.getHeight(),
                    CvType.CV_8UC1);
            Mat grayMat = new Mat(bitmap.getWidth(), bitmap.getHeight(),
                    CvType.CV_8UC1);

            Utils.bitmapToMat(bitmap, mat);

            int colorChannels = (mat.channels() == 3) ? Imgproc.COLOR_BGR2GRAY
                    : ((mat.channels() == 4) ? Imgproc.COLOR_BGRA2GRAY : 1);

            Imgproc.cvtColor(mat, grayMat, colorChannels);


            Imgproc.GaussianBlur(grayMat, grayMat, new Size(9, 9), 2, 2);

            // accumulator value
            double dp = 1.2d;
            // minimum distance between the center coordinates of detected circles in pixels
            double minDist = 100;


            int minRadius = 0, maxRadius = 0;

            double param1 = 70, param2 = 72;


            Mat circles = new Mat(bitmap.getWidth(),
                    bitmap.getHeight(), CvType.CV_8UC1);


            Imgproc.HoughCircles(grayMat, circles,
                    Imgproc.CV_HOUGH_GRADIENT, dp, minDist, param1,
                    param2, minRadius, maxRadius);


            int numberOfCircles = 9;

            if (numberOfCircles > circles.cols()){ 
                numberOfCircles = circles.cols();
             }


            for (int i=0; i<numberOfCircles;  i++) {



                double[] circleCoordinates = circles.get(0, i);



                if(circleCoordinates == null){
                break;
                 }



                int x = (int) circleCoordinates[0], y = (int) circleCoordinates[1];

                Point center = new Point(x, y);
                android.graphics.Point centerC = new android.graphics.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);
Run Code Online (Sandbox Code Playgroud)

提前致谢.

现在我使用那些A形点测试代码,但我想在照片上检测更小的圆圈. 在此输入图像描述

Ole*_*sov 1

我认为,如果你只想检测白色圆圈,你需要实现颜色检测。它不仅会大大提高检测质量,而且会消除大量误报和漏报。使用颜色检测非常简单,因为它已经存在于 OpenCV 中。对于这个使用Core.inRange功能。您可以在这里找到更多相关信息。但对您来说最好的事情可能是遵循教程。它是用 Python 编写的,但它是可以理解的,您只需更改几行即可使其在 Android 上工作。希望这可以帮助 :)