Skip to content

Commit c5bca7b

Browse files
committed
Update find_ellipses.cpp
1 parent 11b056b commit c5bca7b

File tree

3 files changed

+60
-15
lines changed

3 files changed

+60
-15
lines changed

modules/ximgproc/include/opencv2/ximgproc/find_ellipses.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace ximgproc {
1717
@brief Finds ellipses fastly in an image using projective invariant pruning.
1818
*
1919
* The function detects ellipses in images using projective invariant pruning.
20-
* For more details about this implementation, please see
21-
* [JIA2017FAST] Jia, Qi et al, (2017).
20+
* For more details about this implementation, please see @cite jia2017fast
21+
* Jia, Qi et al, (2017).
2222
* A Fast Ellipse Detector using Projective Invariant Pruning. IEEE Transactions on Image Processing.
2323
*
2424
@param image input image, could be gray or color.
@@ -35,4 +35,4 @@ CV_EXPORTS_W void findEllipses(
3535
//! @} ximgproc
3636
}
3737
}
38-
#endif
38+
#endif
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/python
2+
3+
'''
4+
This example illustrates how to use cv.ximgproc.findEllipses function.
5+
6+
Usage:
7+
find_ellipses.py [<image_name>]
8+
image argument defaults to stuff.jpg
9+
'''
10+
11+
# Python 2/3 compatibility
12+
from __future__ import print_function
13+
14+
import numpy as np
15+
import cv2 as cv
16+
import sys
17+
import math
18+
19+
def main():
20+
try:
21+
fn = sys.argv[1]
22+
except IndexError:
23+
fn = 'stuff.jpg'
24+
25+
src = cv.imread(cv.samples.findFile(fn))
26+
cv.imshow("source", src)
27+
28+
ells = cv.ximgproc.findEllipses(src,scoreThreshold = 0.4, reliabilityThreshold = 0.7, centerDistanceThreshold = 0.02)
29+
30+
if ells is not None:
31+
for i in range(len(ells)):
32+
center = (int(ells[i][0][0]), int(ells[i][0][1]))
33+
axes = (int(ells[i][0][2]),int(ells[i][0][3]))
34+
angle = ells[i][0][5] * 180 / math.pi
35+
color = (0, 0, 255)
36+
cv.ellipse(src, center, axes, angle,0, 360, color, 2, cv.LINE_AA)
37+
38+
cv.imshow("detected ellipses", src)
39+
cv.waitKey(0)
40+
print('Done')
41+
42+
43+
if __name__ == '__main__':
44+
print(__doc__)
45+
main()
46+
cv.destroyAllWindows()

modules/ximgproc/src/find_ellipses.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,11 @@ float EllipseDetectorImpl::getMedianSlope(std::vector<Point2f> &med, Point2f &ce
310310
// centers : centroid of the points in med
311311
// slopes : vector of the slopes
312312

313-
unsigned pointCount = med.size();
313+
size_t pointCount = med.size();
314314
// CV_Assert(pointCount >= 2);
315315

316-
unsigned halfSize = pointCount >> 1;
317-
unsigned quarterSize = halfSize >> 1;
316+
size_t halfSize = pointCount >> 1;
317+
size_t quarterSize = halfSize >> 1;
318318

319319
std::vector<float> xx, yy;
320320
slopes.reserve(halfSize);
@@ -1341,7 +1341,7 @@ void EllipseDetectorImpl::preProcessing(Mat1b &image, Mat1b &dp, Mat1b &dn) {
13411341
}
13421342

13431343
const int CANNY_SHIFT = 15;
1344-
const float TAN22_5 = 0.4142135623730950488016887242097; // tan(22.5) = sqrt(2) - 1
1344+
const float TAN22_5 = 0.4142135623730950488016887242097f; // tan(22.5) = sqrt(2) - 1
13451345
const int TG22 = (int) (TAN22_5 * (1 << CANNY_SHIFT) + 0.5);
13461346

13471347
// #define CANNY_PUSH(d) *(d) = (uchar)2, *stack_top++ = (d)
@@ -1723,8 +1723,8 @@ void EllipseDetectorImpl::findEllipses(Point2f &center, VP &edge_i, VP &edge_j,
17231723
}
17241724

17251725
// find peak in N and K accumulator
1726-
int iN = std::distance(accN, std::max_element(accN, accN + ACC_N_SIZE));
1727-
int iK = std::distance(accR, std::max_element(accR, accR + ACC_R_SIZE)) + 90;
1726+
int iN = (int)std::distance(accN, std::max_element(accN, accN + ACC_N_SIZE));
1727+
int iK = (int)std::distance(accR, std::max_element(accR, accR + ACC_R_SIZE)) + 90;
17281728

17291729
// recover real values
17301730
auto fK = float(iK);
@@ -1767,7 +1767,7 @@ void EllipseDetectorImpl::findEllipses(Point2f &center, VP &edge_i, VP &edge_j,
17671767
}
17681768

17691769
// find peak in A accumulator
1770-
int A = std::distance(accA, std::max_element(accA, accA + ACC_A_SIZE));
1770+
int A = (int)std::distance(accA, std::max_element(accA, accA + ACC_A_SIZE));
17711771
auto fA = float(A);
17721772

17731773
// find B value. See Eq [23] in the paper
@@ -1974,15 +1974,14 @@ void findEllipses(
19741974
edi.detect(grayImage, ellipseResults);
19751975

19761976
// convert - ellipse format to std::vector<Vec6f>
1977-
auto ellipseSize = unsigned(ellipseResults.size());
1978-
Mat _ellipses(1, ellipseSize, CV_32FC(6));
1979-
for (unsigned i = 0; i < ellipseSize; i++) {
1977+
std::vector<Vec6f> _ellipses;
1978+
for (size_t i = 0; i < ellipseResults.size(); i++) {
19801979
Ellipse tmpEll = ellipseResults[i];
19811980
Vec6f tmpVec(tmpEll.center.x, tmpEll.center.y, tmpEll.a, tmpEll.b, tmpEll.score,
19821981
tmpEll.radius);
1983-
_ellipses.at<Vec6f>(i) = tmpVec;
1982+
_ellipses.push_back(tmpVec);
19841983
}
1985-
_ellipses.copyTo(ellipses);
1984+
Mat(_ellipses).copyTo(ellipses);
19861985
}
19871986
} // namespace ximgproc
19881987
} // namespace cv

0 commit comments

Comments
 (0)