2012-12-27 16 views
8

Android用OpenCVを使用して、画像中に表示されている、見られているドミノのすべての点の合計を計算するAndroidアプリを開発しています。OpenCV:ドミノサークルスポット/ディスク検出

a sample

問題は、私は他の輪郭をフィルタリングし、私がドミノに表示ドットのみをカウントする方法を見つけることができません、ですが、私は、その後、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;   
} 

EDIT:

私は岩の絶対的な上面図を持っていないとHoughCirclesは完璧な円を検出するようにのみここで

:)は、私のコードです

スレッショルド後の私の輪郭のユニークな特徴の一つは、内側から完全に黒色です。それで、とにかく、私は与えられた輪郭の平均色/強度を計算できますか?

+0

この図では、 –

+0

ちょうどそれを追加、ごめんなさい –

答えて

5

SOに類似の問題と考えられる解決方法があります。Detection of coins (and fit ellipses) on an imageと題されています。ここでは、opencvの機能fitEllipseに関するいくつかの勧告があります。 をご覧ください。

また、イメージ内の黒い要素のみを検出するために、HSVカラーモデルを使用して黒色のみを検出することができます。あなたはfind an explanation hereできます。