【问题标题】:OpenCV: Dominoes circular spots/disks detectionOpenCV:多米诺骨牌圆点/圆盘检测
【发布时间】:2012-12-13 01:27:54
【问题描述】:

我正在开发一个 Android 应用程序,该应用程序使用 OpenCV for Android 计算正在看到的多米诺骨牌的所有点的总和 - 如图所示。

问题是,我找不到过滤其他轮廓并仅计算我在多米诺骨牌中看到的点的方法,我尝试使用 Canny 边缘查找然后使用 HoughCircles,但没有结果,因为我没有岩石的绝对顶视图,HoughCircles 仅检测完美的圆圈:)

这是我的代码:

public Mat onCameraFrame(Mat inputFrame) {
    inputFrame.copyTo(mRgba);

    Mat grey = new Mat();
    // Make it greyscale
    Imgproc.cvtColor(mRgba, grey, Imgproc.COLOR_RGBA2GRAY);

    // init contours arraylist
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>(200);     

    //blur
    Imgproc.GaussianBlur(grey, grey, new Size(9,9), 10);        
    Imgproc.threshold(grey, grey, 80, 150, Imgproc.THRESH_BINARY);


    // because findContours modifies the image I back it up
    Mat greyCopy = new Mat();
    grey.copyTo(greyCopy);


    Imgproc.findContours(greyCopy, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_NONE);      
    // Now I have my controus pefectly


    MatOfPoint2f mMOP2f1 = new MatOfPoint2f();

    //a list for only selected contours
    List<MatOfPoint> SelectedContours = new ArrayList<MatOfPoint>(400);     

    for(int i=0;i<contours.size();i++)
    {

        if(here I should put a condition that distinguishes my spots, eg: if contour inside is black and is a black disk)
        {
            SelectedContours.add(contours.get(i));
        }
    }
    Imgproc.drawContours(mRgba, SelectedContours, -1, new Scalar(255,0,0,255), 1);       
    return mRgba;        
}

编辑:

我的轮廓在阈值之后的一个独特特征是它们从内部完全是黑色的,无论如何我可以计算给定轮廓的平均颜色/强度吗?

【问题讨论】:

    标签: java android opencv


    【解决方案1】:

    在 SO 上有一个类似的问题和可能的解决方案,标题为 Detection of coins (and fit ellipses) on an image。在这里你会找到一些关于opencv函数fitEllipse的推荐。

    你应该看看this for more info on opencv's function fitEllipse

    此外,要仅检测图像中的黑色元素,您可以使用 HSV 颜色模型,仅查找黑色。你可以find an explanation here

    【讨论】:

      猜你喜欢
      • 2022-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-01
      • 2017-05-24
      • 1970-01-01
      相关资源
      最近更新 更多