2013-07-28 2 views
0

640x480
가 다운로드 해주세요 여기 도시 하나이다 원본 이미지는 여기 1280x1024검색/피팅 서클 2.4.6 목적은 원은 검출 될 필요가있는 image.The 테스트 이미지에서 5 흰색 원을 검출하는

다양한 원형/타원 감지 방법을 평가하는 데 다른 방법을 사용하고 있습니다. 그러나 어떻게 든 나는 간단한 Hough 변환 코드를 고칠 수 없다. 서클을 감지하지 못합니다. 문제가 전처리 단계인지 또는 HoughCircle의 매개 변수인지 여부는 명확하지 않습니다. 나는 포럼에서 이와 비슷한 질문들을 모두 마쳤지 만 여전히 문제를 해결할 수는 없다. 이것은 내 코드입니다.

헤더 파일 ..이 관해서 제발 도와주세요

#ifndef IMGPROCESSOR_H 
    #define IMGPROCESSOR_H 

    // OpenCV Library 
    #include <opencv2\opencv.hpp> 
    #include <iostream> 

    using namespace cv; 
    using namespace std; 

    class ImgProcessor{ 
    public: 
     Mat OpImg ; 
     ImgProcessor(); 
     ~ImgProcessor(); 

     //aquire filter methods to image 
     int Do_Hough(Mat IpImg); 

    }; 
    #endif /* ImgProcessor_H */ 

소스 파일의 코드는, 좋은 다른 것 같다

#include "ImgProcessor.h" 
#include <opencv2\opencv.hpp> 
#include "opencv2\imgproc\imgproc.hpp" 
#include "opencv2\imgproc\imgproc_c.h" 
#include <vector> 

using namespace cv; 


ImgProcessor::ImgProcessor(){ 
    return; 
} 
ImgProcessor::~ImgProcessor(){ 
    return; 
} 

//Apply filtering for the input image 
int ImgProcessor::Do_Hough(Mat IpImg) 

{ 
    //Parameter Initialization________________________________________________________ 
    double sigma_x, sigma_y, thresh=250, max_thresh = 255; 
    int ksize_w = 5 ; 
    int ksize_h = 5; 
    sigma_x = 0.3*((ksize_w-1)*0.5 - 1) + 0.8 ; 
    sigma_y = 0.3*((ksize_h-1)*0.5 - 1) + 0.8 ; 

    vector<Vec3f> circles; 

    //Read the image as a matrix 
    Mat TempImg; 
    //resize(IpImg, IpImg ,Size(), 0.5,0.5, INTER_AREA); 

    //Preprocessing__________________________________________________________ 

    //Perform initial smoothing 
    GaussianBlur(IpImg, TempImg, Size(ksize_w, ksize_h),2,2); 

    //perform thresholding 
    threshold(TempImg,TempImg, thresh,thresh, 0); 

    //Remove noise by gaussian smoothing 
    GaussianBlur(TempImg, TempImg, Size(ksize_w, ksize_h),2,2); 
    /*imshow("Noisefree Image", TempImg); 
    waitKey(10000);*/ 

    //Obtain edges 
    Canny(TempImg, TempImg, 255,240 , 3); 
    imshow("See Edges", TempImg); 
    waitKey(10000); 

    //Increase the line thickness 
    //dilate(TempImg,TempImg,0,Point(-1,-1),3); 

    //Hough Circle Method______________________________________________________________ 

    // Apply the Hough Transform to find the circles 
    HoughCircles(TempImg, circles, 3, 1, TempImg.rows/32, 255, 240, 5, 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(IpImg, center, 3, Scalar(0,255,0), -1, 8, 0); 
     // circle outline 
     circle(IpImg, center, radius, Scalar(0,0,255), 3, 8, 0); 
    } 

    // Show your results 
    namedWindow("Hough Circle Transform", WINDOW_AUTOSIZE); 
    imshow("Hough Circle Transform", IpImg); 

    // waitKey(0); 
    return 0; 





} 

int main(int argc, char** argv) 
{ 
    ImgProcessor Iclass; 
    //char* imageName = argv[1]; 
    string imageName = "D:/Projects/test_2707/test_2707/1.bmp"; 
    Mat IpImg = imread(imageName); 
    cvtColor(IpImg, IpImg,6,CV_8UC1); 
    Iclass.Do_Hough(IpImg); 
    /*Iclass.Do_Contours(IpImg);*/ 
    return 0; 
} 

답변

0

보다 :에

HoughCircles(TempImg, circles, 3, 1, TempImg.rows/32, 255, 240, 5, 0); 

가 3 번을합니까 매개 변수 목록은 CV_HOUGH_GRADIENT에 해당합니까? 숫자 대신 정의를 사용하는 것이 항상 좋습니다.

더 큰 원이있는 이미지로 먼저 테스트해야 할 수도 있습니다. 코드의 나머지 부분이 정확하면 HoughCircles의 매개 변수를 조정할 수 있습니다.

+0

네, 실제로 ** CV_HOUGH_GRADIENT **에 해당합니다. 나는 귀하의 제안을 받아들이고 앞으로도 동일하게 수행 할 것입니다. 나는 또한 무작위로 Google에서 얻은 다른 테스트 이미지를 사용해 보았는데 모두 알고리즘과 함께 잘 작동하는 것 같습니다. – Robionic

+0

좋습니다. 매개 변수 테스트가 완료되었습니다. 찾고있는 최소 반경은 5 픽셀이며 크기가 조정 된 이미지의 픽셀 크기와 거의 같습니다. 최대 반경 0은 제한이 없음을 의미합니다. – Totoro

+0

최소 반지름을 3보다 작게 줄이고 다시 시도하십시오. 그 이유가 원의 작은 크기인지, 누적 기 버퍼의 점수가 낮아지는 지 궁금합니다. 윤곽선을 가져 와서 윤곽선 길이를 사용하여 올바른 크기의 원을 감지 할 수도 있습니다. – Totoro