8

Android用のOpenCVを使用して、見られているドミノピースのすべてのポイントの合計を計算する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;        
}

編集:

しきい値後の輪郭のユニークな機能の 1 つは、内側から完全に黒くなっていることです。とにかく、特定の輪郭の平均色/強度を計算できますか?

4

1 に答える 1

5

SO には、イメージ上のコインの検出 (および楕円の適合)というタイトルの同様の問題と可能な解決策があります。ここでは、opencv の機能に関する推奨事項をいくつか紹介しますfitEllipse

opencv の function の詳細については、これをfitEllipse参照してください。

また、画像内の黒色の要素のみを検出するには、HSV カラー モデルを使用して黒色のみを検出します。ここで説明を見つけることができます。

于 2012-12-28T07:28:01.287 に答える