Skip to content

Commit 11b056b

Browse files
authored
Merge pull request #3322 from MisakiCoca:ellipse
1 parent ff5da1e commit 11b056b

File tree

8 files changed

+2159
-0
lines changed

8 files changed

+2159
-0
lines changed

modules/ximgproc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ Extended Image Processing
1616
- Pei&Lin Normalization
1717
- Ridge Detection Filter
1818
- Binary morphology on run-length encoded images
19+
- Ellipse Detector

modules/ximgproc/doc/ximgproc.bib

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,3 +389,14 @@ @article{loke2021accelerated
389389
year={2021},
390390
publisher={Springer}
391391
}
392+
393+
@article{jia2017fast,
394+
title={A fast ellipse detector using projective invariant pruning},
395+
author={Jia, Qi and Fan, Xin and Luo, Zhongxuan and Song, Lianbo and Qiu, Tie},
396+
journal={IEEE Transactions on Image Processing},
397+
volume={26},
398+
number={8},
399+
pages={3665--3679},
400+
year={2017},
401+
publisher={IEEE}
402+
}

modules/ximgproc/include/opencv2/ximgproc.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
#include "ximgproc/edgepreserving_filter.hpp"
6363
#include "ximgproc/color_match.hpp"
6464
#include "ximgproc/radon_transform.hpp"
65+
#include "ximgproc/find_ellipses.hpp"
6566

6667

6768
/** @defgroup ximgproc Extended Image Processing
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#ifndef __OPENCV_FIND_ELLIPSES_HPP__
6+
#define __OPENCV_FIND_ELLIPSES_HPP__
7+
8+
#include <opencv2/core.hpp>
9+
10+
namespace cv {
11+
namespace ximgproc {
12+
13+
//! @addtogroup ximgproc
14+
//! @{
15+
16+
/**
17+
@brief Finds ellipses fastly in an image using projective invariant pruning.
18+
*
19+
* 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).
22+
* A Fast Ellipse Detector using Projective Invariant Pruning. IEEE Transactions on Image Processing.
23+
*
24+
@param image input image, could be gray or color.
25+
@param ellipses output vector of found ellipses. each vector is encoded as five float $x, y, a, b, radius, score$.
26+
@param scoreThreshold float, the threshold of ellipse score.
27+
@param reliabilityThreshold float, the threshold of reliability.
28+
@param centerDistanceThreshold float, the threshold of center distance.
29+
*/
30+
CV_EXPORTS_W void findEllipses(
31+
InputArray image, OutputArray ellipses,
32+
float scoreThreshold = 0.7f, float reliabilityThreshold = 0.5f,
33+
float centerDistanceThreshold = 0.05f
34+
);
35+
//! @} ximgproc
36+
}
37+
}
38+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
#include "perf_precomp.hpp"
5+
6+
namespace opencv_test { namespace {
7+
8+
typedef tuple<Size, MatType, int> FindEllipsesTestParam;
9+
typedef TestBaseWithParam<FindEllipsesTestParam> FindEllipsesTest;
10+
11+
PERF_TEST_P(FindEllipsesTest, perf, Combine(SZ_TYPICAL, Values(CV_8U), Values(1, 3)))
12+
{
13+
FindEllipsesTestParam params = GetParam();
14+
Size sz = get<0>(params);
15+
int matType = get<1>(params);
16+
int srcCn = get<2>(params);
17+
18+
Mat src(sz, CV_MAKE_TYPE(matType, srcCn));
19+
Mat dst(sz, CV_32FC(6));
20+
21+
declare.in(src, WARMUP_RNG).out(dst);
22+
23+
TEST_CYCLE() findEllipses(src, dst, 0.7f, 0.5f, 0.05f);
24+
25+
SANITY_CHECK_NOTHING();
26+
}
27+
}} // namespace
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
#include <iostream>
6+
#include <opencv2/imgproc.hpp>
7+
#include <opencv2/imgcodecs.hpp>
8+
#include <opencv2/ximgproc.hpp>
9+
#include <opencv2/highgui.hpp>
10+
11+
using namespace cv;
12+
13+
int main() {
14+
15+
// load image
16+
Mat img = imread(samples::findFile("stuff.jpg"), IMREAD_COLOR);
17+
18+
// check if image is loaded
19+
if (img.empty()) {
20+
std::cout << "fail to open image" << std::endl;
21+
return EXIT_FAILURE;
22+
}
23+
24+
// create output array
25+
std::vector<Vec6f> ells;
26+
27+
// test ellipse detection
28+
cv::ximgproc::findEllipses(img, ells, 0.4f, 0.7f, 0.02f);
29+
30+
// print output
31+
for (unsigned i = 0; i < ells.size(); i++) {
32+
Vec6f ell = ells[i];
33+
std::cout << ell << std::endl;
34+
Scalar color(0, 0, 255);
35+
// draw ellipse on image
36+
ellipse(
37+
img,
38+
Point(cvRound(ell[0]), cvRound(ell[1])),
39+
Size(cvRound(ell[2]), cvRound(ell[3])),
40+
ell[5] * 180 / CV_PI, 0.0, 360.0, color, 3
41+
);
42+
}
43+
44+
// show image
45+
imshow("result", img);
46+
waitKey();
47+
48+
// end
49+
return 0;
50+
}

0 commit comments

Comments
 (0)