-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathcvHoughCircles.cpp
More file actions
32 lines (25 loc) · 894 Bytes
/
cvHoughCircles.cpp
File metadata and controls
32 lines (25 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// cvHoughCircles.cpp
// LearningOpenCV
//
// Created by YourtionGuo on 7/28/16.
// Copyright © 2016 Yourtion. All rights reserved.
//
#include <iostream>
#include <highgui.h>
#include <cv.h>
int main(int argc, const char * argv[]) {
IplImage* image = cvLoadImage(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
CvMemStorage* storage = cvCreateMemStorage(0);
cvSmooth(image, image, CV_GAUSSIAN, 5, 5);
CvSeq* results = cvHoughCircles( image, storage, CV_HOUGH_GRADIENT, 2, image->width/10 );
for ( int i = 0; i < results->total ; i++ ) {
float* p = (float *) cvGetSeqElem( results, i);
CvPoint pt = cvPoint( cvRound(p[0]), cvRound(p[1]) );
cvCircle(image, pt, cvRound(p[2]), CV_RGB(0xff, 0xff, 0xff));
}
cvNamedWindow( "cvHoughCircles", 1 );
cvShowImage( "cvHoughCircles", image );
cvWaitKey(0);
return 0;
}