mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 00:03:03 +04:00
Merge pull request #3443 from HelenWong:bug3363Fix
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
@@ -1024,10 +1024,14 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist,
|
||||
CvSeqReader reader;
|
||||
|
||||
edges.reset(cvCreateMat( img->rows, img->cols, CV_8UC1 ));
|
||||
|
||||
// Use the Canny Edge Detector to detect all the edges in the image.
|
||||
cvCanny( img, edges, MAX(canny_threshold/2,1), canny_threshold, 3 );
|
||||
|
||||
dx.reset(cvCreateMat( img->rows, img->cols, CV_16SC1 ));
|
||||
dy.reset(cvCreateMat( img->rows, img->cols, CV_16SC1 ));
|
||||
|
||||
/*Use the Sobel Derivative to compute the local gradient of all the non-zero pixels in the edge image.*/
|
||||
cvSobel( img, dx, 1, 0, 3 );
|
||||
cvSobel( img, dy, 0, 1, 3 );
|
||||
|
||||
@@ -1038,6 +1042,8 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist,
|
||||
cvZero(accum);
|
||||
|
||||
storage.reset(cvCreateMemStorage());
|
||||
/* Create sequences for the nonzero pixels in the edge image and the centers of circles
|
||||
which could be detected.*/
|
||||
nz = cvCreateSeq( CV_32SC2, sizeof(CvSeq), sizeof(CvPoint), storage );
|
||||
centers = cvCreateSeq( CV_32SC1, sizeof(CvSeq), sizeof(int), storage );
|
||||
|
||||
@@ -1118,7 +1124,8 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist,
|
||||
|
||||
sort_buf.resize( MAX(center_count,nz_count) );
|
||||
cvCvtSeqToArray( centers, &sort_buf[0] );
|
||||
|
||||
/*Sort candidate centers in descending order of their accumulator values, so that the centers
|
||||
with the most supporting pixels appear first.*/
|
||||
std::sort(sort_buf.begin(), sort_buf.begin() + center_count, cv::hough_cmp_gt(adata));
|
||||
cvClearSeq( centers );
|
||||
cvSeqPushMulti( centers, &sort_buf[0], center_count );
|
||||
@@ -1173,6 +1180,7 @@ icvHoughCirclesGradient( CvMat* img, float dp, float min_dist,
|
||||
continue;
|
||||
dist_buf->cols = nz_count1;
|
||||
cvPow( dist_buf, dist_buf, 0.5 );
|
||||
// Sort non-zero pixels according to their distance from the center.
|
||||
std::sort(sort_buf.begin(), sort_buf.begin() + nz_count1, cv::hough_cmp_gt((int*)ddata));
|
||||
|
||||
dist_sum = start_dist = ddata[sort_buf[nz_count1-1]];
|
||||
|
||||
Reference in New Issue
Block a user