Skip to content

Commit 592f8d8

Browse files
TomBecker-BDalalek
authored andcommitted
Merge pull request opencv#10232 from TomBecker-BD:hough-many-circles
Hough many circles (opencv#10232) * Add Hui's optimization. Merge with latest changes in OpenCV. * Use conditional compilation instead of a runtime flag. * Whitespace. * Create the sequence for the nonzero edge pixels only if using that approach. * Improve performance for finding very large numbers of circles * Return the circles with the larger accumulator values first, as per API documentation. Use a separate step to check distance between circles. Allows circles to be sorted by strength first. Avoids locking in EstimateRadius which was slowing it down. Return centers only if maxRadius == 0 as per API documentation. * Sort the circles so results are deterministic. Otherwise the order of circles with the same strength depends on parallel processing completion order. * Add test for HoughCircles. * Add beads test. * Wrap the non-zero points structure in a common interface so the code can use either a vector or a matrix. * Remove the special case for skipping the radius search if maxRadius==0. * Add performance tests. * Use NULL instead of nullptr. OpenCV should compile with C++98 compiler. * Put test suite name first. Use different test suite names for each test to avoid an error from the test runner. * Address build bot errors and warnings. * Skip radius search if maxRadius < 0. * Dynamically switch to NZPointList when it will be faster than NZPointSet. * Fix compile error: missing 'typename' prior to dependent type name. * Fix compile error: missing 'typename' prior to dependent type name. This time fix it the non C++ 11 way. * Fix compile error: no type named 'const_reference' in 'class cv::NZPointList' * Disable ManySmallCircles tests. Failing on Mac. * Change beads image to JPEG for smaller file size. Try enabling the ManySmallCircles tests again. * Remove ManySmallCircles tests. They are failing on the Mac build. * Fix expectations to check all circles. * Changing case on a case-insensitive file system Step 1: remove the old file names * Changing case on a case-insensitive file system Step 2: add them back with the new names * Fix cmpAccum function to be strictly weak ordered. * Add tests for many small circles. * imgproc(perf): fix HoughCircles tests * imgproc(houghCircles): refactor code - simplify NZPointList - drop broken (de-synchronization of 'current'/'mi' fields) NZPointSet iterator - NZPointSet iterator is replaced to direct area scan - use SIMD intrinsics - avoid std exceptions (build for embedded systems)
1 parent d9c0231 commit 592f8d8

File tree

4 files changed

+681
-281
lines changed

4 files changed

+681
-281
lines changed

modules/imgproc/include/opencv2/imgproc.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,8 +2094,8 @@ Example: :
20942094
20952095
@note Usually the function detects the centers of circles well. However, it may fail to find correct
20962096
radii. You can assist to the function by specifying the radius range ( minRadius and maxRadius ) if
2097-
you know it. Or, you may set maxRadius to 0 to return centers only without radius search, and find the correct
2098-
radius using an additional procedure.
2097+
you know it. Or, you may set maxRadius to a negative number to return centers only without radius
2098+
search, and find the correct radius using an additional procedure.
20992099
21002100
@param image 8-bit, single-channel, grayscale input image.
21012101
@param circles Output vector of found circles. Each vector is encoded as a 3-element
@@ -2114,7 +2114,8 @@ accumulator threshold for the circle centers at the detection stage. The smaller
21142114
false circles may be detected. Circles, corresponding to the larger accumulator values, will be
21152115
returned first.
21162116
@param minRadius Minimum circle radius.
2117-
@param maxRadius Maximum circle radius.
2117+
@param maxRadius Maximum circle radius. If <= 0, uses the maximum image dimension. If < 0, returns
2118+
centers without finding the radius.
21182119
21192120
@sa fitEllipse, minEnclosingCircle
21202121
*/
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#include "perf_precomp.hpp"
2+
#include "opencv2/imgproc.hpp"
3+
#include "opencv2/imgproc/types_c.h"
4+
5+
using namespace std;
6+
using namespace cv;
7+
using namespace perf;
8+
9+
PERF_TEST(PerfHoughCircles, Basic)
10+
{
11+
string filename = getDataPath("cv/imgproc/stuff.jpg");
12+
const double dp = 1.0;
13+
double minDist = 20;
14+
double edgeThreshold = 20;
15+
double accumThreshold = 30;
16+
int minRadius = 20;
17+
int maxRadius = 200;
18+
19+
Mat img = imread(filename, IMREAD_GRAYSCALE);
20+
ASSERT_FALSE(img.empty()) << "Unable to load source image " << filename;
21+
22+
GaussianBlur(img, img, Size(9, 9), 2, 2);
23+
24+
vector<Vec3f> circles;
25+
declare.in(img);
26+
27+
TEST_CYCLE()
28+
{
29+
HoughCircles(img, circles, CV_HOUGH_GRADIENT, dp, minDist, edgeThreshold, accumThreshold, minRadius, maxRadius);
30+
}
31+
32+
SANITY_CHECK_NOTHING();
33+
}
34+
35+
PERF_TEST(PerfHoughCircles2, ManySmallCircles)
36+
{
37+
string filename = getDataPath("cv/imgproc/beads.jpg");
38+
const double dp = 1.0;
39+
double minDist = 10;
40+
double edgeThreshold = 90;
41+
double accumThreshold = 11;
42+
int minRadius = 7;
43+
int maxRadius = 18;
44+
45+
Mat img = imread(filename, IMREAD_GRAYSCALE);
46+
ASSERT_FALSE(img.empty()) << "Unable to load source image " << filename;
47+
48+
vector<Vec3f> circles;
49+
declare.in(img);
50+
51+
TEST_CYCLE()
52+
{
53+
HoughCircles(img, circles, CV_HOUGH_GRADIENT, dp, minDist, edgeThreshold, accumThreshold, minRadius, maxRadius);
54+
}
55+
56+
SANITY_CHECK_NOTHING();
57+
}

0 commit comments

Comments
 (0)