1
0
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:
Alexander Alekhin
2021-04-07 18:30:36 +00:00
4 changed files with 49 additions and 12 deletions

View File

@@ -65,8 +65,9 @@ public:
hysteresis procedure in Canny()
@param _canny_th2 50 - Second threshold for
hysteresis procedure in Canny()
@param _canny_aperture_size 3 - Aperturesize for the sobel
operator in Canny()
@param _canny_aperture_size 3 - Aperturesize for the sobel 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
will be performed
*/

View File

@@ -37,8 +37,9 @@ int main(int argc, char** argv)
// hysteresis procedure in Canny()
// canny_th2 50 - Second threshold for
// hysteresis procedure in Canny()
// canny_aperture_size 3 - Aperturesize for the sobel
// operator in Canny()
// canny_aperture_size 3 - Aperturesize for the sobel 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
// will be performed
int length_threshold = 10;

View File

@@ -29,10 +29,11 @@ class FastLineDetectorImpl : public FastLineDetector
* _ hysteresis procedure in Canny()
* @param _canny_th2 50 - Second threshold for
* _ hysteresis procedure in Canny()
* @param _canny_aperture_size 3 - Aperturesize for the sobel
* _ operator in Canny()
* @param _canny_aperture_size 3 - Aperturesize for the sobel 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
will be perfomred
* will be performed
*/
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,
@@ -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)
{
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)
@@ -544,8 +545,14 @@ void FastLineDetectorImpl::lineDetection(const Mat& src, std::vector<SEGMENT>& s
std::vector<Point2i> points;
std::vector<SEGMENT> segments, segments_tmp;
Mat canny;
if (canny_aperture_size == 0)
{
canny = src;
}
else
{
Canny(src, canny, canny_th1, canny_th2, canny_aperture_size);
}
canny.colRange(0,6).rowRange(0,6) = 0;
canny.colRange(src.cols-5,src.cols).rowRange(src.rows-5,src.rows) = 0;

View File

@@ -23,6 +23,7 @@ class FLDBase : public testing::Test
void GenerateWhiteNoise(Mat& image);
void GenerateConstColor(Mat& image);
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 GenerateRotatedRect(Mat& image);
virtual void SetUp();
@@ -55,6 +56,7 @@ void FLDBase::GenerateConstColor(Mat& image)
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 256)));
}
void FLDBase::GenerateLines(Mat& image, const unsigned int numLines)
{
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)
{
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);
}
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)
{
for (int i = 0; i < EPOCHS; ++i)