2016-12-11 18 views
0

OpenCVの新機能です。ペニー画像だけを検出しようとしていますが、小さな円がたくさんあります。誰かが間違っていることを教えてもらえますか?ここからopencvは複数の小さな円を検出しますが、それより大きいものは検出しません

コード:私は画像を600x480になりますので、ペニー円は少なくとも400

でなければなりません知っているので https://github.com/opencv/opencv/blob/master/samples/cpp/houghcircles.cpp

は、私だけが変わっ事が分円の半径400、および円0の最大を作ることでしたあなたは、半径およびジを持って

#include "opencv2/imgcodecs.hpp" 
#include "opencv2/highgui.hpp" 
#include "opencv2/imgproc.hpp" 

#include <iostream> 

using namespace cv; 
using namespace std; 

static void help() 
{ 
    cout << "\nThis program demonstrates circle finding with the Hough transform.\n" 
      "Usage:\n" 
      "./houghcircles <image_name>, Default is ../data/board.jpg\n" << endl; 
} 

int main(int argc, char** argv) 
{ 
    cv::CommandLineParser parser(argc, argv, 
     "{help h ||}{@image|../data/board.jpg|}" 
    ); 
    if (parser.has("help")) 
    { 
     help(); 
     return 0; 
    } 
    //![load] 
    string filename = parser.get<string>("@image"); 
    Mat img = imread(filename, IMREAD_COLOR); 
    if(img.empty()) 
    { 
     help(); 
     cout << "can not open " << filename << endl; 
     return -1; 
    } 
    //![load] 

    //![convert_to_gray] 
    Mat gray; 
    cvtColor(img, gray, COLOR_BGR2GRAY); 
    //![convert_to_gray] 

    //![reduce_noise] 
    medianBlur(gray, gray, 5); 
    //![reduce_noise] 

    //![houghcircles] 
    vector<Vec3f> circles; 
    HoughCircles(gray, circles, HOUGH_GRADIENT, 1, 
       gray.rows/16, // change this value to detect circles with different distances to each other 
       100, 30, 400,0 // change the last two parameters 
           // (min_radius & max_radius) to detect larger circles 
       ); 
    //![houghcircles] 

    //![draw] 
    for(size_t i = 0; i < circles.size(); i++) 
    { 
     Vec3i c = circles[i]; 
     circle(img, Point(c[0], c[1]), c[2], Scalar(0,0,255), 3, LINE_AA); 
     circle(img, Point(c[0], c[1]), 2, Scalar(0,255,0), 3, LINE_AA); 
    } 
    //![draw] 

    //![display] 
    imshow("detected circles", img); 
    waitKey(); 
    //![display] 

    return 0; 
} 

enter image description here

enter image description here

+0

オフセットを付けてサークルを描画しているように見えます。同じ画像に対してより簡単なテスト(例:閾値処理)を試してください。 –

+0

関数のparam1とparam2をそれぞれ200と100に設定してみてください。より正確な結果が得られる可能性があります。http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.html – TomJ

答えて

1
HoughCircles(gray, circles, HOUGH_GRADIENT, 1, 
      max(gray.cols,gray.rows), // to find only the biggest perfect circle 
      100, 100, 0,0 // leave other params as default 

);

enter image description here

2

ameterが混ざり合った。画像が600×480のみの場合、最小半径は400にできません。 min_radiusを200に設定します。

+0

あなたは正しいですが、それでも問題は完全に解決されませんでした – Rilcon42

関連する問題