mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-16 22:35:51 +08:00
Merge pull request #2915 from alalek:backport_2716
This commit is contained in:
@@ -65,8 +65,9 @@ public:
|
|||||||
hysteresis procedure in Canny()
|
hysteresis procedure in Canny()
|
||||||
@param _canny_th2 50 - Second threshold for
|
@param _canny_th2 50 - Second threshold for
|
||||||
hysteresis procedure in Canny()
|
hysteresis procedure in Canny()
|
||||||
@param _canny_aperture_size 3 - Aperturesize for the sobel
|
@param _canny_aperture_size 3 - Aperturesize for the sobel operator in Canny().
|
||||||
operator in Canny()
|
If zero, Canny() is not applied and the input
|
||||||
|
image is taken as an edge image.
|
||||||
@param _do_merge false - If true, incremental merging of segments
|
@param _do_merge false - If true, incremental merging of segments
|
||||||
will be performed
|
will be performed
|
||||||
*/
|
*/
|
||||||
|
@@ -37,8 +37,9 @@ int main(int argc, char** argv)
|
|||||||
// hysteresis procedure in Canny()
|
// hysteresis procedure in Canny()
|
||||||
// canny_th2 50 - Second threshold for
|
// canny_th2 50 - Second threshold for
|
||||||
// hysteresis procedure in Canny()
|
// hysteresis procedure in Canny()
|
||||||
// canny_aperture_size 3 - Aperturesize for the sobel
|
// canny_aperture_size 3 - Aperturesize for the sobel operator in Canny().
|
||||||
// operator in Canny()
|
// If zero, Canny() is not applied and the input
|
||||||
|
// image is taken as an edge image.
|
||||||
// do_merge false - If true, incremental merging of segments
|
// do_merge false - If true, incremental merging of segments
|
||||||
// will be performed
|
// will be performed
|
||||||
int length_threshold = 10;
|
int length_threshold = 10;
|
||||||
|
@@ -29,10 +29,11 @@ class FastLineDetectorImpl : public FastLineDetector
|
|||||||
* _ hysteresis procedure in Canny()
|
* _ hysteresis procedure in Canny()
|
||||||
* @param _canny_th2 50 - Second threshold for
|
* @param _canny_th2 50 - Second threshold for
|
||||||
* _ hysteresis procedure in Canny()
|
* _ hysteresis procedure in Canny()
|
||||||
* @param _canny_aperture_size 3 - Aperturesize for the sobel
|
* @param _canny_aperture_size 3 - Aperturesize for the sobel operator in Canny().
|
||||||
* _ operator in Canny()
|
* If zero, Canny() is not applied and the input
|
||||||
|
* image is taken as an edge image.
|
||||||
* @param _do_merge false - If true, incremental merging of segments
|
* @param _do_merge false - If true, incremental merging of segments
|
||||||
will be perfomred
|
* will be performed
|
||||||
*/
|
*/
|
||||||
FastLineDetectorImpl(int _length_threshold = 10, float _distance_threshold = 1.414213562f,
|
FastLineDetectorImpl(int _length_threshold = 10, float _distance_threshold = 1.414213562f,
|
||||||
double _canny_th1 = 50.0, double _canny_th2 = 50.0, int _canny_aperture_size = 3,
|
double _canny_th1 = 50.0, double _canny_th2 = 50.0, int _canny_aperture_size = 3,
|
||||||
@@ -80,7 +81,7 @@ class FastLineDetectorImpl : public FastLineDetector
|
|||||||
|
|
||||||
double distPointLine(const Mat& p, Mat& l);
|
double distPointLine(const Mat& p, Mat& l);
|
||||||
|
|
||||||
void extractSegments(const std::vector<Point2i>& points, std::vector<SEGMENT>& segments );
|
void extractSegments(const std::vector<Point2i>& points, std::vector<SEGMENT>& segments);
|
||||||
|
|
||||||
void lineDetection(const Mat& src, std::vector<SEGMENT>& segments_all);
|
void lineDetection(const Mat& src, std::vector<SEGMENT>& segments_all);
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ FastLineDetectorImpl::FastLineDetectorImpl(int _length_threshold, float _distanc
|
|||||||
canny_th1(_canny_th1), canny_th2(_canny_th2), canny_aperture_size(_canny_aperture_size), do_merge(_do_merge)
|
canny_th1(_canny_th1), canny_th2(_canny_th2), canny_aperture_size(_canny_aperture_size), do_merge(_do_merge)
|
||||||
{
|
{
|
||||||
CV_Assert(_length_threshold > 0 && _distance_threshold > 0 &&
|
CV_Assert(_length_threshold > 0 && _distance_threshold > 0 &&
|
||||||
_canny_th1 > 0 && _canny_th2 > 0 && _canny_aperture_size > 0);
|
_canny_th1 > 0 && _canny_th2 > 0 && _canny_aperture_size >= 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FastLineDetectorImpl::detect(InputArray _image, OutputArray _lines)
|
void FastLineDetectorImpl::detect(InputArray _image, OutputArray _lines)
|
||||||
@@ -344,7 +345,7 @@ template<class T>
|
|||||||
pt = T(pt_tmp);
|
pt = T(pt_tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FastLineDetectorImpl::extractSegments(const std::vector<Point2i>& points, std::vector<SEGMENT>& segments )
|
void FastLineDetectorImpl::extractSegments(const std::vector<Point2i>& points, std::vector<SEGMENT>& segments)
|
||||||
{
|
{
|
||||||
bool is_line;
|
bool is_line;
|
||||||
|
|
||||||
@@ -544,8 +545,14 @@ void FastLineDetectorImpl::lineDetection(const Mat& src, std::vector<SEGMENT>& s
|
|||||||
std::vector<Point2i> points;
|
std::vector<Point2i> points;
|
||||||
std::vector<SEGMENT> segments, segments_tmp;
|
std::vector<SEGMENT> segments, segments_tmp;
|
||||||
Mat canny;
|
Mat canny;
|
||||||
|
if (canny_aperture_size == 0)
|
||||||
|
{
|
||||||
|
canny = src;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Canny(src, canny, canny_th1, canny_th2, canny_aperture_size);
|
Canny(src, canny, canny_th1, canny_th2, canny_aperture_size);
|
||||||
|
}
|
||||||
canny.colRange(0,6).rowRange(0,6) = 0;
|
canny.colRange(0,6).rowRange(0,6) = 0;
|
||||||
canny.colRange(src.cols-5,src.cols).rowRange(src.rows-5,src.rows) = 0;
|
canny.colRange(src.cols-5,src.cols).rowRange(src.rows-5,src.rows) = 0;
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@ class FLDBase : public testing::Test
|
|||||||
void GenerateWhiteNoise(Mat& image);
|
void GenerateWhiteNoise(Mat& image);
|
||||||
void GenerateConstColor(Mat& image);
|
void GenerateConstColor(Mat& image);
|
||||||
void GenerateLines(Mat& image, const unsigned int numLines);
|
void GenerateLines(Mat& image, const unsigned int numLines);
|
||||||
|
void GenerateEdgeLines(Mat& image, const unsigned int numLines);
|
||||||
void GenerateBrokenLines(Mat& image, const unsigned int numLines);
|
void GenerateBrokenLines(Mat& image, const unsigned int numLines);
|
||||||
void GenerateRotatedRect(Mat& image);
|
void GenerateRotatedRect(Mat& image);
|
||||||
virtual void SetUp();
|
virtual void SetUp();
|
||||||
@@ -55,6 +56,7 @@ void FLDBase::GenerateConstColor(Mat& image)
|
|||||||
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 256)));
|
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 256)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FLDBase::GenerateLines(Mat& image, const unsigned int numLines)
|
void FLDBase::GenerateLines(Mat& image, const unsigned int numLines)
|
||||||
{
|
{
|
||||||
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128)));
|
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128)));
|
||||||
@@ -68,6 +70,19 @@ void FLDBase::GenerateLines(Mat& image, const unsigned int numLines)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FLDBase::GenerateEdgeLines(Mat& image, const unsigned int numLines)
|
||||||
|
{
|
||||||
|
image = Mat(img_size, CV_8UC1, Scalar::all(0));
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < numLines; ++i)
|
||||||
|
{
|
||||||
|
int y = rng.uniform(10, img_size.width - 10);
|
||||||
|
Point p1(y, 10);
|
||||||
|
Point p2(y, img_size.height - 10);
|
||||||
|
line(image, p1, p2, Scalar(255), 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FLDBase::GenerateBrokenLines(Mat& image, const unsigned int numLines)
|
void FLDBase::GenerateBrokenLines(Mat& image, const unsigned int numLines)
|
||||||
{
|
{
|
||||||
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128)));
|
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128)));
|
||||||
@@ -153,6 +168,19 @@ TEST_F(ximgproc_FLD, lines)
|
|||||||
ASSERT_EQ(EPOCHS, passedtests);
|
ASSERT_EQ(EPOCHS, passedtests);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ximgproc_FLD, edgeLines)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < EPOCHS; ++i)
|
||||||
|
{
|
||||||
|
const unsigned int numOfLines = 1;
|
||||||
|
GenerateEdgeLines(test_image, numOfLines);
|
||||||
|
Ptr<FastLineDetector> detector = createFastLineDetector(10, 1.414213562f, 50, 50, 0);
|
||||||
|
detector->detect(test_image, lines);
|
||||||
|
if(numOfLines == lines.size()) ++passedtests;
|
||||||
|
}
|
||||||
|
ASSERT_EQ(EPOCHS, passedtests);
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(ximgproc_FLD, mergeLines)
|
TEST_F(ximgproc_FLD, mergeLines)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < EPOCHS; ++i)
|
for (int i = 0; i < EPOCHS; ++i)
|
||||||
|
Reference in New Issue
Block a user