首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV: Dominoes圆形斑点/磁盘检测

OpenCV: Dominoes圆形斑点/磁盘检测
EN

Stack Overflow用户
提问于 2012-12-28 01:05:19
回答 1查看 3.6K关注 0票数 8

我正在开发一个安卓应用程序,计算所有的点被看到的多米诺骨牌块图片-shown的总和-使用安卓的OpenCV。

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

下面是我的代码:

代码语言:javascript
复制
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;        
}

编辑:

阈值之后,我的轮廓的一个独特特征是它们从内部完全是黑色的,有没有什么我可以计算给定轮廓的平均颜色/强度?

EN

回答 1

Stack Overflow用户

发布于 2012-12-28 15:28:01

在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

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14058366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档