From: Daniel Angelov Date: Sun, 21 Jul 2013 21:55:29 +0000 (+0300) Subject: Update on the class. Edited tests and samples. X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~3832^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6fa4834f31e53878a0d70fa4df0b3dd84f05c945;p=platform%2Fupstream%2Fopencv.git Update on the class. Edited tests and samples. --- diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 1dec4ce..dd849ef 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -883,18 +883,11 @@ public: */ virtual int compareSegments(const Size& size, const InputArray lines1, const InputArray lines2, Mat* image = 0) = 0; - ~LineSegmentDetector() {}; -protected: - LineSegmentDetector() {}; + virtual ~LineSegmentDetector() {}; }; //! Returns a pointer to a LineSegmentDetector class. -CV_EXPORTS Ptr createLineSegmentDetectorSmrtPtr( - int _refine = LSD_REFINE_STD, double _scale = 0.8, - double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5, - double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024); - -CV_EXPORTS LineSegmentDetector* createLineSegmentDetectorPtr( +CV_EXPORTS Ptr createLineSegmentDetectorPtr( int _refine = LSD_REFINE_STD, double _scale = 0.8, double _sigma_scale = 0.6, double _quant = 2.0, double _ang_th = 22.5, double _log_eps = 0, double _density_th = 0.7, int _n_bins = 1024); diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index 0ab6a9d..b4f228a 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/modules/imgproc/src/lsd.cpp @@ -389,7 +389,7 @@ private: ///////////////////////////////////////////////////////////////////////////////////////// -CV_EXPORTS Ptr createLineSegmentDetectorSmrtPtr( +CV_EXPORTS Ptr createLineSegmentDetectorPtr( int _refine, double _scale, double _sigma_scale, double _quant, double _ang_th, double _log_eps, double _density_th, int _n_bins) { @@ -398,15 +398,6 @@ CV_EXPORTS Ptr createLineSegmentDetectorSmrtPtr( _log_eps, _density_th, _n_bins)); } -CV_EXPORTS LineSegmentDetector* createLineSegmentDetectorPtr( - int _refine, double _scale, double _sigma_scale, double _quant, double _ang_th, - double _log_eps, double _density_th, int _n_bins) -{ - return new LineSegmentDetectorImpl( - _refine, _scale, _sigma_scale, _quant, _ang_th, - _log_eps, _density_th, _n_bins); -} - ///////////////////////////////////////////////////////////////////////////////////////// LineSegmentDetectorImpl::LineSegmentDetectorImpl(int _refine, double _scale, double _sigma_scale, double _quant, diff --git a/modules/imgproc/test/test_lsd.cpp b/modules/imgproc/test/test_lsd.cpp index edb095a..e18f32f 100644 --- a/modules/imgproc/test/test_lsd.cpp +++ b/modules/imgproc/test/test_lsd.cpp @@ -6,6 +6,8 @@ using namespace cv; using namespace std; const Size img_size(640, 480); +const int LSD_TEST_SEED = 0x134679; +const int EPOCHS = 20; class LSDBase : public testing::Test { @@ -15,6 +17,8 @@ public: protected: Mat test_image; vector lines; + RNG rng; + int passedtests; void GenerateWhiteNoise(Mat& image); void GenerateConstColor(Mat& image); @@ -50,19 +54,16 @@ protected: void LSDBase::GenerateWhiteNoise(Mat& image) { image = Mat(img_size, CV_8UC1); - RNG rng(getTickCount()); rng.fill(image, RNG::UNIFORM, 0, 256); } void LSDBase::GenerateConstColor(Mat& image) { - RNG rng(getTickCount()); image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 256))); } void LSDBase::GenerateLines(Mat& image, const unsigned int numLines) { - RNG rng(getTickCount()); image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128))); for(unsigned int i = 0; i < numLines; ++i) @@ -76,7 +77,6 @@ void LSDBase::GenerateLines(Mat& image, const unsigned int numLines) void LSDBase::GenerateRotatedRect(Mat& image) { - RNG rng(getTickCount()); image = Mat::zeros(img_size, CV_8UC1); Point center(rng.uniform(img_size.width/4, img_size.width*3/4), @@ -100,116 +100,166 @@ void LSDBase::SetUp() { lines.clear(); test_image = Mat(); + rng = RNG(LSD_TEST_SEED); + passedtests = 0; } TEST_F(Imgproc_LSD_ADV, whiteNoise) { - GenerateWhiteNoise(test_image); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + GenerateWhiteNoise(test_image); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); + detector->detect(test_image, lines); - ASSERT_GE((unsigned int)(40), lines.size()); + if(uint(40) >= lines.size()) ++passedtests; + } + ASSERT_EQ(EPOCHS, passedtests); } TEST_F(Imgproc_LSD_ADV, constColor) { - GenerateConstColor(test_image); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + GenerateConstColor(test_image); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); + detector->detect(test_image, lines); - ASSERT_EQ((unsigned int)(0), lines.size()); + if(uint(0) == lines.size()) ++passedtests; + } + ASSERT_EQ(EPOCHS, passedtests); } TEST_F(Imgproc_LSD_ADV, lines) { - const unsigned int numOfLines = 1; - GenerateLines(test_image, numOfLines); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + const unsigned int numOfLines = 1; + GenerateLines(test_image, numOfLines); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); + detector->detect(test_image, lines); - ASSERT_EQ(numOfLines * 2, lines.size()); // * 2 because of Gibbs effect + if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect + } + ASSERT_EQ(EPOCHS, passedtests); } TEST_F(Imgproc_LSD_ADV, rotatedRect) { - GenerateRotatedRect(test_image); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + GenerateRotatedRect(test_image); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_ADV); + detector->detect(test_image, lines); - ASSERT_LE((unsigned int)(2), lines.size()); + if(uint(2) <= lines.size()) ++passedtests; + } + ASSERT_EQ(EPOCHS, passedtests); } TEST_F(Imgproc_LSD_STD, whiteNoise) { - GenerateWhiteNoise(test_image); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + GenerateWhiteNoise(test_image); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); + detector->detect(test_image, lines); - ASSERT_GE((unsigned int)(50), lines.size()); + if(uint(50) >= lines.size()) ++passedtests; + } + ASSERT_EQ(EPOCHS, passedtests); } TEST_F(Imgproc_LSD_STD, constColor) { - GenerateConstColor(test_image); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + GenerateConstColor(test_image); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); + detector->detect(test_image, lines); - ASSERT_EQ((unsigned int)(0), lines.size()); + if(uint(0) == lines.size()) ++passedtests; + } + ASSERT_EQ(EPOCHS, passedtests); } TEST_F(Imgproc_LSD_STD, lines) { - const unsigned int numOfLines = 1; - GenerateLines(test_image, numOfLines); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + const unsigned int numOfLines = 1; + GenerateLines(test_image, numOfLines); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); + detector->detect(test_image, lines); - ASSERT_EQ(numOfLines * 2, lines.size()); // * 2 because of Gibbs effect + if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect + } + ASSERT_EQ(EPOCHS, passedtests); } TEST_F(Imgproc_LSD_STD, rotatedRect) { - GenerateRotatedRect(test_image); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + GenerateRotatedRect(test_image); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); + detector->detect(test_image, lines); - ASSERT_LE((unsigned int)(4), lines.size()); + if(uint(4) <= lines.size()) ++passedtests; + } + ASSERT_EQ(EPOCHS, passedtests); } TEST_F(Imgproc_LSD_NONE, whiteNoise) { - GenerateWhiteNoise(test_image); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + GenerateWhiteNoise(test_image); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_STD); + detector->detect(test_image, lines); - ASSERT_GE((unsigned int)(50), lines.size()); + if(uint(50) >= lines.size()) ++passedtests; + } + ASSERT_EQ(EPOCHS, passedtests); } TEST_F(Imgproc_LSD_NONE, constColor) { - GenerateConstColor(test_image); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_NONE); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + GenerateConstColor(test_image); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_NONE); + detector->detect(test_image, lines); - ASSERT_EQ((unsigned int)(0), lines.size()); + if(uint(0) == lines.size()) ++passedtests; + } + ASSERT_EQ(EPOCHS, passedtests); } TEST_F(Imgproc_LSD_NONE, lines) { - const unsigned int numOfLines = 1; - GenerateLines(test_image, numOfLines); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_NONE); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + const unsigned int numOfLines = 1; + GenerateLines(test_image, numOfLines); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_NONE); + detector->detect(test_image, lines); - ASSERT_EQ(numOfLines * 2, lines.size()); // * 2 because of Gibbs effect + if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect + } + ASSERT_EQ(EPOCHS, passedtests); } TEST_F(Imgproc_LSD_NONE, rotatedRect) { - GenerateRotatedRect(test_image); - LineSegmentDetector* detector = createLineSegmentDetectorPtr(LSD_REFINE_NONE); - detector->detect(test_image, lines); + for (int i = 0; i < EPOCHS; ++i) + { + GenerateRotatedRect(test_image); + Ptr detector = createLineSegmentDetectorPtr(LSD_REFINE_NONE); + detector->detect(test_image, lines); - ASSERT_LE((unsigned int)(8), lines.size()); + if(uint(8) <= lines.size()) ++passedtests; + } + ASSERT_EQ(EPOCHS, passedtests); }