Skip to content

new feature: update ellipse detector using projective invariant pruning #3322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/ximgproc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Extended Image Processing
- Pei&Lin Normalization
- Ridge Detection Filter
- Binary morphology on run-length encoded images
- Ellipse Detector
11 changes: 11 additions & 0 deletions modules/ximgproc/doc/ximgproc.bib
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,14 @@ @article{loke2021accelerated
year={2021},
publisher={Springer}
}

@article{jia2017fast,
title={A fast ellipse detector using projective invariant pruning},
author={Jia, Qi and Fan, Xin and Luo, Zhongxuan and Song, Lianbo and Qiu, Tie},
journal={IEEE Transactions on Image Processing},
volume={26},
number={8},
pages={3665--3679},
year={2017},
publisher={IEEE}
}
1 change: 1 addition & 0 deletions modules/ximgproc/include/opencv2/ximgproc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include "ximgproc/edgepreserving_filter.hpp"
#include "ximgproc/color_match.hpp"
#include "ximgproc/radon_transform.hpp"
#include "ximgproc/find_ellipses.hpp"


/** @defgroup ximgproc Extended Image Processing
Expand Down
38 changes: 38 additions & 0 deletions modules/ximgproc/include/opencv2/ximgproc/find_ellipses.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

#ifndef __OPENCV_FIND_ELLIPSES_HPP__
#define __OPENCV_FIND_ELLIPSES_HPP__

#include <opencv2/core.hpp>

namespace cv {
namespace ximgproc {

//! @addtogroup ximgproc
//! @{

/**
@brief Finds ellipses fastly in an image using projective invariant pruning.
*
* The function detects ellipses in images using projective invariant pruning.
* For more details about this implementation, please see
* [JIA2017FAST] Jia, Qi et al, (2017).
* A Fast Ellipse Detector using Projective Invariant Pruning. IEEE Transactions on Image Processing.
*
@param image input image, could be gray or color.
@param ellipses output vector of found ellipses. each vector is encoded as five float $x, y, a, b, radius, score$.
@param scoreThreshold float, the threshold of ellipse score.
@param reliabilityThreshold float, the threshold of reliability.
@param centerDistanceThreshold float, the threshold of center distance.
*/
CV_EXPORTS_W void findEllipses(
InputArray image, OutputArray ellipses,
float scoreThreshold = 0.7f, float reliabilityThreshold = 0.5f,
float centerDistanceThreshold = 0.05f
);
//! @} ximgproc
}
}
#endif
27 changes: 27 additions & 0 deletions modules/ximgproc/perf/perf_find_ellipses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#include "perf_precomp.hpp"

namespace opencv_test { namespace {

typedef tuple<Size, MatType, int> FindEllipsesTestParam;
typedef TestBaseWithParam<FindEllipsesTestParam> FindEllipsesTest;

PERF_TEST_P(FindEllipsesTest, perf, Combine(SZ_TYPICAL, Values(CV_8U), Values(1, 3)))
{
FindEllipsesTestParam params = GetParam();
Size sz = get<0>(params);
int matType = get<1>(params);
int srcCn = get<2>(params);

Mat src(sz, CV_MAKE_TYPE(matType, srcCn));
Mat dst(sz, CV_32FC(6));

declare.in(src, WARMUP_RNG).out(dst);

TEST_CYCLE() findEllipses(src, dst, 0.7f, 0.5f, 0.05f);

SANITY_CHECK_NOTHING();
}
}} // namespace
50 changes: 50 additions & 0 deletions modules/ximgproc/samples/find_ellipses.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

#include <iostream>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/ximgproc.hpp>
#include <opencv2/highgui.hpp>

using namespace cv;

int main() {

// load image
Mat img = imread(samples::findFile("stuff.jpg"), IMREAD_COLOR);

// check if image is loaded
if (img.empty()) {
std::cout << "fail to open image" << std::endl;
return EXIT_FAILURE;
}

// create output array
std::vector<Vec6f> ells;

// test ellipse detection
cv::ximgproc::findEllipses(img, ells, 0.4f, 0.7f, 0.02f);

// print output
for (unsigned i = 0; i < ells.size(); i++) {
Vec6f ell = ells[i];
std::cout << ell << std::endl;
Scalar color(0, 0, 255);
// draw ellipse on image
ellipse(
img,
Point(cvRound(ell[0]), cvRound(ell[1])),
Size(cvRound(ell[2]), cvRound(ell[3])),
ell[5] * 180 / CV_PI, 0.0, 360.0, color, 3
);
}

// show image
imshow("result", img);
waitKey();

// end
return 0;
}
Loading