【问题标题】:Detecting Hough circles android检测霍夫圆android
【发布时间】:2012-02-25 15:00:49
【问题描述】:

我正在尝试使用 android 检测圆圈。我成功实现了检测线算法,但在尝试绘制霍夫圆算法时没有显示任何内容。

这是我的代码:

Mat thresholdImage = new Mat(getFrameHeight() + getFrameHeight() / 2, getFrameWidth(), CvType.CV_8UC1);
            mYuv.put(0, 0, data);
            Imgproc.cvtColor(mYuv, destination, Imgproc.COLOR_YUV420sp2RGB, 4);
            Imgproc.cvtColor(destination, thresholdImage, Imgproc.COLOR_RGB2GRAY, 4);
            Imgproc.GaussianBlur(thresholdImage, thresholdImage, new Size(9, 9), 2, 2 );

        Mat circles = new Mat();


        Imgproc.HoughCircles(thresholdImage, circles, Imgproc.CV_HOUGH_GRADIENT, 1d, (double)thresholdImage.height()/70, 200d, 100d);

        Log.w("circles", circles.cols()+"");
        for (int x = 0; x < circles.cols(); x++) 
        {
                double vCircle[]=circles.get(0,x);

                Point center=new Point(Math.round(vCircle[0]), Math.round(vCircle[1]));
                int radius = (int)Math.round(vCircle[2]);
                // draw the circle center
                Core.circle(destination, center, 3,new Scalar(0,255,0), -1, 8, 0 );
                // draw the circle outline
                Core.circle( destination, center, radius, new Scalar(0,0,255), 3, 8, 0 );

        }

【问题讨论】:

    标签: java android opencv geometry


    【解决方案1】:

    您现在可能已经对此进行了排序,但有几件事。我会检查你的圈子垫实际上有一些结果;有时 vCircle 似乎返回 null;尝试其他版本的 HoughCircles 之一:

    iCannyUpperThreshold = 100;
    iMinRadius = 20;
    iMaxRadius = 400;
    iAccumulator = 300;
    
    Imgproc.HoughCircles(thresholdImage, circles, Imgproc.CV_HOUGH_GRADIENT, 
             2.0, thresholdImage.rows() / 8, iCannyUpperThreshold, iAccumulator, 
             iMinRadius, iMaxRadius);
    
    if (circles.cols() > 0)
        for (int x = 0; x < circles.cols(); x++) 
            {
            double vCircle[] = circles.get(0,x);
    
            if (vCircle == null)
                break;
    
            Point pt = new Point(Math.round(vCircle[0]), Math.round(vCircle[1]));
            int radius = (int)Math.round(vCircle[2]);
    
            // draw the found circle
            Core.circle(destination, pt, radius, new Scalar(0,255,0), iLineThickness);
            Core.circle(destination, pt, 3, new Scalar(0,0,255), iLineThickness);
            }
    

    (我把你的代码换成了我的,重命名了一些东西并把它换回来,我认为我把它拿回来了,所以它可以工作了......)

    乙。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-29
      • 2019-04-14
      • 2015-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多