2017-01-09 9 views
0

문제가 있습니다. 나는 코드가 :이 웹 사이트에서 OpenCV에서 예입니다OpenCV가 그림에서 원을 감지하지 못합니다.

#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/imgproc/imgproc.hpp" 
#include <iostream> 
#include <stdio.h> 

using namespace cv; 
using namespace std; 

/** @function main */ 
int main(int argc, char** argv) 
{ 
    Mat src, src_gray; 

    /// Read the image 
    src = imread(argv[1], 1); 

    if(!src.data) 
    { return -1; } 

    /// Convert it to gray 
    cvtColor(src, src_gray, CV_BGR2GRAY); 

    /// Reduce the noise so we avoid false circle detection 
    GaussianBlur(src_gray, src_gray, Size(9, 9), 2, 2); 

    vector<Vec3f> circles; 

    /// Apply the Hough Transform to find the circles 
    HoughCircles(src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0); 

    /// Draw the circles detected 
    for(size_t i = 0; i < circles.size(); i++) 
    { 
     Point center(cvRound(circles[i][0]), cvRound(circles[i][1])); 
     int radius = cvRound(circles[i][2]); 
     // circle center 
     circle(src, center, 3, Scalar(0,255,0), -1, 8, 0); 
     // circle outline 
     circle(src, center, radius, Scalar(0,0,255), 3, 8, 0); 
    } 

    /// Show your results 
    namedWindow("Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE); 
    imshow("Hough Circle Transform Demo", src); 

    waitKey(0); 
    return 0; 
} 

을 (http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.html)

나는 다음과 같은 그림이 : 코드에서 OpenCV하지 않는 위의 이미지에 대한

Image

을 circle.size()가 0인지 확인하십시오.

어떻게해야합니까? 코드를 수정하려면?

+0

MSalters가 지적한 것처럼 원의 최소/최대 반지름과 두 개의 원이 분리되기를 원하는 최소 거리와 같은 몇 가지 매개 변수를 확인해야합니다. 이러한 수정은 코드 스 니펫의'HoughCircles()'에서 수행됩니다. :) –

답변

0

원과 큰 차이가있는 이미지 (태양 광)에는 기본 임계 값 (200 및 100)을 사용하고 있습니다. 프로그래밍 오류가 아니라 데이터/설정 문제 일뿐입니다.