From 690725980ccd4df9a5f8da44c0e1144f4a35375c Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 30 Oct 2020 00:57:09 +0000 Subject: [PATCH] imgproc: drop LineSegmentDetector stubs --- modules/imgproc/include/opencv2/imgproc.hpp | 90 ----- modules/imgproc/src/lsd.cpp | 264 ------------- modules/imgproc/test/test_lsd.cpp | 409 -------------------- 3 files changed, 763 deletions(-) delete mode 100644 modules/imgproc/src/lsd.cpp delete mode 100644 modules/imgproc/test/test_lsd.cpp diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 4a41ba6b50..57d639d64b 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -480,14 +480,6 @@ enum HoughModes { HOUGH_GRADIENT_ALT = 4, //!< variation of HOUGH_GRADIENT to get better accuracy }; -//! Variants of Line Segment %Detector -enum LineSegmentDetectorModes { - LSD_REFINE_NONE = 0, //!< No refinement applied - LSD_REFINE_STD = 1, //!< Standard refinement is applied. E.g. breaking arches into smaller straighter line approximations. - LSD_REFINE_ADV = 2 //!< Advanced refinement. Number of false alarms is calculated, lines are - //!< refined through increase of precision, decrement in size, etc. -}; - //! @} imgproc_feature /** Histogram comparison methods @@ -1251,88 +1243,6 @@ protected: //! @} imgproc_subdiv2d -//! @addtogroup imgproc_feature -//! @{ - -/** @brief Line segment detector class - -following the algorithm described at @cite Rafael12 . - -@note Implementation has been removed due original code license conflict - -*/ -class CV_EXPORTS_W LineSegmentDetector : public Algorithm -{ -public: - - /** @brief Finds lines in the input image. - - This is the output of the default parameters of the algorithm on the above shown image. - - ![image](pics/building_lsd.png) - - @param _image A grayscale (CV_8UC1) input image. If only a roi needs to be selected, use: - `lsd_ptr-\>detect(image(roi), lines, ...); lines += Scalar(roi.x, roi.y, roi.x, roi.y);` - @param _lines A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. Where - Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. Returned lines are strictly - oriented depending on the gradient. - @param width Vector of widths of the regions, where the lines are found. E.g. Width of line. - @param prec Vector of precisions with which the lines are found. - @param nfa Vector containing number of false alarms in the line region, with precision of 10%. The - bigger the value, logarithmically better the detection. - - -1 corresponds to 10 mean false alarms - - 0 corresponds to 1 mean false alarm - - 1 corresponds to 0.1 mean false alarms - This vector will be calculated only when the objects type is #LSD_REFINE_ADV. - */ - CV_WRAP virtual void detect(InputArray _image, OutputArray _lines, - OutputArray width = noArray(), OutputArray prec = noArray(), - OutputArray nfa = noArray()) = 0; - - /** @brief Draws the line segments on a given image. - @param _image The image, where the lines will be drawn. Should be bigger or equal to the image, - where the lines were found. - @param lines A vector of the lines that needed to be drawn. - */ - CV_WRAP virtual void drawSegments(InputOutputArray _image, InputArray lines) = 0; - - /** @brief Draws two groups of lines in blue and red, counting the non overlapping (mismatching) pixels. - - @param size The size of the image, where lines1 and lines2 were found. - @param lines1 The first group of lines that needs to be drawn. It is visualized in blue color. - @param lines2 The second group of lines. They visualized in red color. - @param _image Optional image, where the lines will be drawn. The image should be color(3-channel) - in order for lines1 and lines2 to be drawn in the above mentioned colors. - */ - CV_WRAP virtual int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) = 0; - - virtual ~LineSegmentDetector() { } -}; - -/** @brief Creates a smart pointer to a LineSegmentDetector object and initializes it. - -The LineSegmentDetector algorithm is defined using the standard values. Only advanced users may want -to edit those, as to tailor it for their own application. - -@param _refine The way found lines will be refined, see #LineSegmentDetectorModes -@param _scale The scale of the image that will be used to find the lines. Range (0..1]. -@param _sigma_scale Sigma for Gaussian filter. It is computed as sigma = _sigma_scale/_scale. -@param _quant Bound to the quantization error on the gradient norm. -@param _ang_th Gradient angle tolerance in degrees. -@param _log_eps Detection threshold: -log10(NFA) \> log_eps. Used only when advance refinement -is chosen. -@param _density_th Minimal density of aligned region points in the enclosing rectangle. -@param _n_bins Number of bins in pseudo-ordering of gradient modulus. - -@note Implementation has been removed due original code license conflict - */ -CV_EXPORTS_W Ptr createLineSegmentDetector( - 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); - -//! @} imgproc_feature - //! @addtogroup imgproc_filter //! @{ diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp deleted file mode 100644 index af022811d1..0000000000 --- a/modules/imgproc/src/lsd.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/*M/////////////////////////////////////////////////////////////////////////////////////// -// -// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. -// -// By downloading, copying, installing or using the software you agree to this license. -// If you do not agree to this license, do not download, install, -// copy or use the software. -// -// -// License Agreement -// For Open Source Computer Vision Library -// -// Copyright (C) 2013, OpenCV Foundation, all rights reserved. -// Third party copyrights are property of their respective owners. -// -// Redistribution and use in source and binary forms, with or without modification, -// are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// * The name of the copyright holders may not be used to endorse or promote products -// derived from this software without specific prior written permission. -// -// This software is provided by the copyright holders and contributors "as is" and -// any express or implied warranties, including, but not limited to, the implied -// warranties of merchantability and fitness for a particular purpose are disclaimed. -// In no event shall the Intel Corporation or contributors be liable for any direct, -// indirect, incidental, special, exemplary, or consequential damages -// (including, but not limited to, procurement of substitute goods or services; -// loss of use, data, or profits; or business interruption) however caused -// and on any theory of liability, whether in contract, strict liability, -// or tort (including negligence or otherwise) arising in any way out of -// the use of this software, even if advised of the possibility of such damage. -// -//M*/ - -#include "precomp.hpp" -#include - -#if defined(_MSC_VER) -# pragma warning(disable:4702) // unreachable code -#endif - -namespace cv { - -class LineSegmentDetectorImpl CV_FINAL : public LineSegmentDetector -{ -public: - -/** - * Create a LineSegmentDetectorImpl object. Specifying scale, number of subdivisions for the image, should the lines be refined and other constants as follows: - * - * @param _refine How should the lines found be refined? - * LSD_REFINE_NONE - No refinement applied. - * LSD_REFINE_STD - Standard refinement is applied. E.g. breaking arches into smaller line approximations. - * LSD_REFINE_ADV - Advanced refinement. Number of false alarms is calculated, - * lines are refined through increase of precision, decrement in size, etc. - * @param _scale The scale of the image that will be used to find the lines. Range (0..1]. - * @param _sigma_scale Sigma for Gaussian filter is computed as sigma = _sigma_scale/_scale. - * @param _quant Bound to the quantization error on the gradient norm. - * @param _ang_th Gradient angle tolerance in degrees. - * @param _log_eps Detection threshold: -log10(NFA) > _log_eps - * @param _density_th Minimal density of aligned region points in rectangle. - * @param _n_bins Number of bins in pseudo-ordering of gradient modulus. - */ - LineSegmentDetectorImpl(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); - -/** - * Detect lines in the input image. - * - * @param _image A grayscale(CV_8UC1) input image. - * If only a roi needs to be selected, use - * lsd_ptr->detect(image(roi), ..., lines); - * lines += Scalar(roi.x, roi.y, roi.x, roi.y); - * @param _lines Return: A vector of Vec4i or Vec4f elements specifying the beginning and ending point of a line. - * Where Vec4i/Vec4f is (x1, y1, x2, y2), point 1 is the start, point 2 - end. - * Returned lines are strictly oriented depending on the gradient. - * @param width Return: Vector of widths of the regions, where the lines are found. E.g. Width of line. - * @param prec Return: Vector of precisions with which the lines are found. - * @param nfa Return: Vector containing number of false alarms in the line region, with precision of 10%. - * The bigger the value, logarithmically better the detection. - * * -1 corresponds to 10 mean false alarms - * * 0 corresponds to 1 mean false alarm - * * 1 corresponds to 0.1 mean false alarms - * This vector will be calculated _only_ when the objects type is REFINE_ADV - */ - void detect(InputArray _image, OutputArray _lines, - OutputArray width = noArray(), OutputArray prec = noArray(), - OutputArray nfa = noArray()) CV_OVERRIDE; - -/** - * Draw lines on the given canvas. - * - * @param image The image, where lines will be drawn. - * Should have the size of the image, where the lines were found - * @param lines The lines that need to be drawn - */ - void drawSegments(InputOutputArray _image, InputArray lines) CV_OVERRIDE; - -/** - * Draw both vectors on the image canvas. Uses blue for lines 1 and red for lines 2. - * - * @param size The size of the image, where lines1 and lines2 were found. - * @param lines1 The first lines that need to be drawn. Color - Blue. - * @param lines2 The second lines that need to be drawn. Color - Red. - * @param image An optional image, where lines will be drawn. - * Should have the size of the image, where the lines were found - * @return The number of mismatching pixels between lines1 and lines2. - */ - int compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image = noArray()) CV_OVERRIDE; - -private: - LineSegmentDetectorImpl& operator= (const LineSegmentDetectorImpl&); // to quiet MSVC -}; - -///////////////////////////////////////////////////////////////////////////////////////// - -CV_EXPORTS Ptr createLineSegmentDetector( - int _refine, double _scale, double _sigma_scale, double _quant, double _ang_th, - double _log_eps, double _density_th, int _n_bins) -{ - return makePtr( - _refine, _scale, _sigma_scale, _quant, _ang_th, - _log_eps, _density_th, _n_bins); -} - -///////////////////////////////////////////////////////////////////////////////////////// - -LineSegmentDetectorImpl::LineSegmentDetectorImpl(int _refine, double _scale, double _sigma_scale, double _quant, - double _ang_th, double _log_eps, double _density_th, int _n_bins) -{ - CV_Assert(_scale > 0 && _sigma_scale > 0 && _quant >= 0 && - _ang_th > 0 && _ang_th < 180 && _density_th >= 0 && _density_th < 1 && - _n_bins > 0); - CV_UNUSED(_refine); CV_UNUSED(_log_eps); - CV_Error(Error::StsNotImplemented, "Implementation has been removed due original code license issues"); -} - -void LineSegmentDetectorImpl::detect(InputArray _image, OutputArray _lines, - OutputArray _width, OutputArray _prec, OutputArray _nfa) -{ - CV_INSTRUMENT_REGION(); - - CV_UNUSED(_image); CV_UNUSED(_lines); - CV_UNUSED(_width); CV_UNUSED(_prec); CV_UNUSED(_nfa); - CV_Error(Error::StsNotImplemented, "Implementation has been removed due original code license issues"); -} - -void LineSegmentDetectorImpl::drawSegments(InputOutputArray _image, InputArray lines) -{ - CV_INSTRUMENT_REGION(); - - CV_Assert(!_image.empty() && (_image.channels() == 1 || _image.channels() == 3)); - - if (_image.channels() == 1) - { - cvtColor(_image, _image, COLOR_GRAY2BGR); - } - - Mat _lines = lines.getMat(); - const int N = _lines.checkVector(4); - - CV_Assert(_lines.depth() == CV_32F || _lines.depth() == CV_32S); - - // Draw segments - if (_lines.depth() == CV_32F) - { - for (int i = 0; i < N; ++i) - { - const Vec4f& v = _lines.at(i); - const Point2f b(v[0], v[1]); - const Point2f e(v[2], v[3]); - line(_image, b, e, Scalar(0, 0, 255), 1); - } - } - else - { - for (int i = 0; i < N; ++i) - { - const Vec4i& v = _lines.at(i); - const Point2i b(v[0], v[1]); - const Point2i e(v[2], v[3]); - line(_image, b, e, Scalar(0, 0, 255), 1); - } - } -} - - -int LineSegmentDetectorImpl::compareSegments(const Size& size, InputArray lines1, InputArray lines2, InputOutputArray _image) -{ - CV_INSTRUMENT_REGION(); - - Size sz = size; - if (_image.needed() && _image.size() != size) sz = _image.size(); - CV_Assert(!sz.empty()); - - Mat_ I1 = Mat_::zeros(sz); - Mat_ I2 = Mat_::zeros(sz); - - Mat _lines1 = lines1.getMat(); - Mat _lines2 = lines2.getMat(); - const int N1 = _lines1.checkVector(4); - const int N2 = _lines2.checkVector(4); - - CV_Assert(_lines1.depth() == CV_32F || _lines1.depth() == CV_32S); - CV_Assert(_lines2.depth() == CV_32F || _lines2.depth() == CV_32S); - - if (_lines1.depth() == CV_32S) - _lines1.convertTo(_lines1, CV_32F); - if (_lines2.depth() == CV_32S) - _lines2.convertTo(_lines2, CV_32F); - - // Draw segments - for(int i = 0; i < N1; ++i) - { - const Point2f b(_lines1.at(i)[0], _lines1.at(i)[1]); - const Point2f e(_lines1.at(i)[2], _lines1.at(i)[3]); - line(I1, b, e, Scalar::all(255), 1); - } - for(int i = 0; i < N2; ++i) - { - const Point2f b(_lines2.at(i)[0], _lines2.at(i)[1]); - const Point2f e(_lines2.at(i)[2], _lines2.at(i)[3]); - line(I2, b, e, Scalar::all(255), 1); - } - - // Count the pixels that don't agree - Mat Ixor; - bitwise_xor(I1, I2, Ixor); - int N = countNonZero(Ixor); - - if (_image.needed()) - { - CV_Assert(_image.channels() == 3); - Mat img = _image.getMatRef(); - CV_Assert(img.isContinuous() && I1.isContinuous() && I2.isContinuous()); - - for (unsigned int i = 0; i < I1.total(); ++i) - { - uchar i1 = I1.ptr()[i]; - uchar i2 = I2.ptr()[i]; - if (i1 || i2) - { - unsigned int base_idx = i * 3; - if (i1) img.ptr()[base_idx] = 255; - else img.ptr()[base_idx] = 0; - img.ptr()[base_idx + 1] = 0; - if (i2) img.ptr()[base_idx + 2] = 255; - else img.ptr()[base_idx + 2] = 0; - } - } - } - - return N; -} - -} // namespace cv diff --git a/modules/imgproc/test/test_lsd.cpp b/modules/imgproc/test/test_lsd.cpp deleted file mode 100644 index e162a3c6f4..0000000000 --- a/modules/imgproc/test/test_lsd.cpp +++ /dev/null @@ -1,409 +0,0 @@ -// 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 "test_precomp.hpp" - -namespace opencv_test { namespace { - -#if 0 // LSD implementation has been removed due original code license issues - -const Size img_size(640, 480); -const int LSD_TEST_SEED = 0x134679; -const int EPOCHS = 20; - -class LSDBase : public testing::Test -{ -public: - LSDBase() { } - -protected: - Mat test_image; - vector lines; - RNG rng; - int passedtests; - - void GenerateWhiteNoise(Mat& image); - void GenerateConstColor(Mat& image); - void GenerateLines(Mat& image, const unsigned int numLines); - void GenerateRotatedRect(Mat& image); - virtual void SetUp(); -}; - -class Imgproc_LSD_ADV: public LSDBase -{ -public: - Imgproc_LSD_ADV() { } -protected: - -}; - -class Imgproc_LSD_STD: public LSDBase -{ -public: - Imgproc_LSD_STD() { } -protected: - -}; - -class Imgproc_LSD_NONE: public LSDBase -{ -public: - Imgproc_LSD_NONE() { } -protected: - -}; - -class Imgproc_LSD_Common : public LSDBase -{ -public: - Imgproc_LSD_Common() { } -protected: - -}; - -void LSDBase::GenerateWhiteNoise(Mat& image) -{ - image = Mat(img_size, CV_8UC1); - rng.fill(image, RNG::UNIFORM, 0, 256); -} - -void LSDBase::GenerateConstColor(Mat& image) -{ - image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 256))); -} - -void LSDBase::GenerateLines(Mat& image, const unsigned int numLines) -{ - image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128))); - - 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), 3); - } -} - -void LSDBase::GenerateRotatedRect(Mat& image) -{ - image = Mat::zeros(img_size, CV_8UC1); - - Point center(rng.uniform(img_size.width/4, img_size.width*3/4), - rng.uniform(img_size.height/4, img_size.height*3/4)); - Size rect_size(rng.uniform(img_size.width/8, img_size.width/6), - rng.uniform(img_size.height/8, img_size.height/6)); - float angle = rng.uniform(0.f, 360.f); - - Point2f vertices[4]; - - RotatedRect rRect = RotatedRect(center, rect_size, angle); - - rRect.points(vertices); - for (int i = 0; i < 4; i++) - { - line(image, vertices[i], vertices[(i + 1) % 4], Scalar(255), 3); - } -} - -void LSDBase::SetUp() -{ - lines.clear(); - test_image = Mat(); - rng = RNG(LSD_TEST_SEED); - passedtests = 0; -} - - -TEST_F(Imgproc_LSD_ADV, whiteNoise) -{ - for (int i = 0; i < EPOCHS; ++i) - { - GenerateWhiteNoise(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_ADV); - detector->detect(test_image, lines); - - if(40u >= lines.size()) ++passedtests; - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_ADV, constColor) -{ - for (int i = 0; i < EPOCHS; ++i) - { - GenerateConstColor(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_ADV); - detector->detect(test_image, lines); - - if(0u == lines.size()) ++passedtests; - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_ADV, lines) -{ - for (int i = 0; i < EPOCHS; ++i) - { - const unsigned int numOfLines = 1; - GenerateLines(test_image, numOfLines); - Ptr detector = createLineSegmentDetector(LSD_REFINE_ADV); - detector->detect(test_image, lines); - - if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_ADV, rotatedRect) -{ - for (int i = 0; i < EPOCHS; ++i) - { - GenerateRotatedRect(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_ADV); - detector->detect(test_image, lines); - - if(2u <= lines.size()) ++passedtests; - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_STD, whiteNoise) -{ - for (int i = 0; i < EPOCHS; ++i) - { - GenerateWhiteNoise(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_STD); - detector->detect(test_image, lines); - - if(50u >= lines.size()) ++passedtests; - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_STD, constColor) -{ - for (int i = 0; i < EPOCHS; ++i) - { - GenerateConstColor(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_STD); - detector->detect(test_image, lines); - - if(0u == lines.size()) ++passedtests; - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_STD, lines) -{ - for (int i = 0; i < EPOCHS; ++i) - { - const unsigned int numOfLines = 1; - GenerateLines(test_image, numOfLines); - Ptr detector = createLineSegmentDetector(LSD_REFINE_STD); - detector->detect(test_image, lines); - - if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_STD, rotatedRect) -{ - for (int i = 0; i < EPOCHS; ++i) - { - GenerateRotatedRect(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_STD); - detector->detect(test_image, lines); - - if(4u <= lines.size()) ++passedtests; - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_NONE, whiteNoise) -{ - for (int i = 0; i < EPOCHS; ++i) - { - GenerateWhiteNoise(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_NONE); - detector->detect(test_image, lines); - - if(50u >= lines.size()) ++passedtests; - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_NONE, constColor) -{ - for (int i = 0; i < EPOCHS; ++i) - { - GenerateConstColor(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_NONE); - detector->detect(test_image, lines); - - if(0u == lines.size()) ++passedtests; - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_NONE, lines) -{ - for (int i = 0; i < EPOCHS; ++i) - { - const unsigned int numOfLines = 1; - GenerateLines(test_image, numOfLines); - Ptr detector = createLineSegmentDetector(LSD_REFINE_NONE); - detector->detect(test_image, lines); - - if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_NONE, rotatedRect) -{ - for (int i = 0; i < EPOCHS; ++i) - { - GenerateRotatedRect(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_NONE); - detector->detect(test_image, lines); - - if(8u <= lines.size()) ++passedtests; - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_Common, supportsVec4iResult) -{ - for (int i = 0; i < EPOCHS; ++i) - { - GenerateWhiteNoise(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_STD); - detector->detect(test_image, lines); - - std::vector linesVec4i; - detector->detect(test_image, linesVec4i); - - if (lines.size() == linesVec4i.size()) - { - bool pass = true; - for (size_t lineIndex = 0; pass && lineIndex < lines.size(); lineIndex++) - { - for (int ch = 0; ch < 4; ch++) - { - if (cv::saturate_cast(lines[lineIndex][ch]) != linesVec4i[lineIndex][ch]) - { - pass = false; - break; - } - } - } - if (pass) - ++passedtests; - } - } - ASSERT_EQ(EPOCHS, passedtests); -} - -TEST_F(Imgproc_LSD_Common, drawSegmentsVec4f) -{ - GenerateConstColor(test_image); - - std::vector linesVec4f; - RNG cr(0); // constant seed for deterministic test - for (int j = 0; j < 10; j++) { - linesVec4f.push_back( - Vec4f(float(cr) * test_image.cols, float(cr) * test_image.rows, float(cr) * test_image.cols, float(cr) * test_image.rows)); - } - - Mat actual = Mat::zeros(test_image.size(), CV_8UC3); - Mat expected = Mat::zeros(test_image.size(), CV_8UC3); - - Ptr detector = createLineSegmentDetector(LSD_REFINE_STD); - detector->drawSegments(actual, linesVec4f); - - // something should be drawn - ASSERT_EQ(sum(actual == expected) != Scalar::all(0), true); - - for (size_t lineIndex = 0; lineIndex < linesVec4f.size(); lineIndex++) - { - const Vec4f &v = linesVec4f[lineIndex]; - const Point2f b(v[0], v[1]); - const Point2f e(v[2], v[3]); - line(expected, b, e, Scalar(0, 0, 255), 1); - } - - ASSERT_EQ(sum(actual != expected) == Scalar::all(0), true); -} - -TEST_F(Imgproc_LSD_Common, drawSegmentsVec4i) -{ - GenerateConstColor(test_image); - - std::vector linesVec4i; - RNG cr(0); // constant seed for deterministic test - for (int j = 0; j < 10; j++) { - linesVec4i.push_back( - Vec4i(cr(test_image.cols), cr(test_image.rows), cr(test_image.cols), cr(test_image.rows))); - } - - Mat actual = Mat::zeros(test_image.size(), CV_8UC3); - Mat expected = Mat::zeros(test_image.size(), CV_8UC3); - - Ptr detector = createLineSegmentDetector(LSD_REFINE_STD); - detector->drawSegments(actual, linesVec4i); - - // something should be drawn - ASSERT_EQ(sum(actual == expected) != Scalar::all(0), true); - - for (size_t lineIndex = 0; lineIndex < linesVec4i.size(); lineIndex++) - { - const Vec4f &v = linesVec4i[lineIndex]; - const Point2f b(v[0], v[1]); - const Point2f e(v[2], v[3]); - line(expected, b, e, Scalar(0, 0, 255), 1); - } - - ASSERT_EQ(sum(actual != expected) == Scalar::all(0), true); -} - -TEST_F(Imgproc_LSD_Common, compareSegmentsVec4f) -{ - GenerateConstColor(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_STD); - - std::vector lines1, lines2; - lines1.push_back(Vec4f(0, 0, 100, 200)); - lines2.push_back(Vec4f(0, 0, 100, 200)); - int result1 = detector->compareSegments(test_image.size(), lines1, lines2); - - ASSERT_EQ(result1, 0); - - lines2.push_back(Vec4f(100, 100, 110, 100)); - int result2 = detector->compareSegments(test_image.size(), lines1, lines2); - - ASSERT_EQ(result2, 11); -} - -TEST_F(Imgproc_LSD_Common, compareSegmentsVec4i) -{ - GenerateConstColor(test_image); - Ptr detector = createLineSegmentDetector(LSD_REFINE_STD); - - std::vector lines1, lines2; - lines1.push_back(Vec4i(0, 0, 100, 200)); - lines2.push_back(Vec4i(0, 0, 100, 200)); - int result1 = detector->compareSegments(test_image.size(), lines1, lines2); - - ASSERT_EQ(result1, 0); - - lines2.push_back(Vec4i(100, 100, 110, 100)); - int result2 = detector->compareSegments(test_image.size(), lines1, lines2); - - ASSERT_EQ(result2, 11); -} - -#endif - -}} // namespace