vector<Vec3f> circles;

HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 1, src_gray.rows/8, 200, 100, 0, 0 );

with the arguments:

  • src_gray : 입력 영상(Gray Scale)
  • circles : A vector that stores sets of 3 values: x_{c}, y_{c}, r for each detected circle.
  • CV_HOUGH_GRADIENT : 검출 함수 정의. Currently this is the only one available in OpenCV
  • dp = 1 : 누적기 해상도 (영상 크기 /2)
  • min_dist = src_gray.rows/8 : 검출된 원간의 최소거리
  • param_1 = 200 : 캐니 최대 경계값
  • param_2 = 100* : Threshold for center detection.
  • min_radius = 0 : Minimum radio to be detected. If unknown, put zero as default.
  • max_radius = 0 : Maximum radius to be detected. If unknown, put zero as default




코드


#include <iostream>

#include <opencv2/core/core.hpp>

#include <opencv2/highgui/highgui.hpp>

#include <opencv2/imgproc/imgproc.hpp>



using namespace cv;

using namespace std;


int main()

{

Mat image;

image = imread("image4/circle2.jpg", CV_LOAD_IMAGE_COLOR);


vector<Vec3f> circles;

HoughCircles(

image, // 원본이미지 

circles, 

CV_HOUGH_GRADIENT,

1,   // 누적기 해상도(영상크기/2)

100, // 두 원 간의 최소 거리

100, // 캐니 최대 경계값

50 // 투표 최소 개수

);


cout << "circles.size()= " << circles.size() << endl;

vector<Vec3f>::const_iterator itc = circles.begin();

int k = 0;


while (itc != circles.end()) {


int cx = (*itc)[0];

int cy = (*itc)[1];

int radius = (*itc)[2];


printf("Circles[%d]: (cx , cy)= (%d , %d), r = %d\n", k++, cx, cy, radius);

circle(image, Point(cx, cy), radius, Scalar(0, 0, 255), 2);

++itc;

}


namedWindow("Detected Circles");

imshow("Detected Circles", image);


waitKey(0);


return 0;

}


결과




'Programming > openCV' 카테고리의 다른 글

BGR별 히스토그램 구하기  (0) 2017.04.11
vector에 접근하는 두가지 방법  (0) 2017.04.11
iterator의 개념  (0) 2017.04.04
12. Templet Matching  (0) 2017.04.04
11. Emboss, sketch, 수채화  (0) 2017.04.04

+ Recent posts