2013-07-12 23:25:33 +02:00
|
|
|
#include "test_precomp.hpp"
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace cv;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
const Size img_size(640, 480);
|
2013-07-21 23:55:29 +02:00
|
|
|
const int LSD_TEST_SEED = 0x134679;
|
|
|
|
const int EPOCHS = 20;
|
2013-07-12 23:25:33 +02:00
|
|
|
|
|
|
|
class LSDBase : public testing::Test
|
|
|
|
{
|
|
|
|
public:
|
2014-01-17 22:30:29 +01:00
|
|
|
LSDBase() { }
|
2013-07-12 23:25:33 +02:00
|
|
|
|
|
|
|
protected:
|
2013-07-14 11:56:22 +02:00
|
|
|
Mat test_image;
|
|
|
|
vector<Vec4i> lines;
|
2013-07-21 23:55:29 +02:00
|
|
|
RNG rng;
|
|
|
|
int passedtests;
|
2013-07-14 11:56:22 +02:00
|
|
|
|
|
|
|
void GenerateWhiteNoise(Mat& image);
|
|
|
|
void GenerateConstColor(Mat& image);
|
|
|
|
void GenerateLines(Mat& image, const unsigned int numLines);
|
|
|
|
void GenerateRotatedRect(Mat& image);
|
|
|
|
virtual void SetUp();
|
2013-07-12 23:25:33 +02:00
|
|
|
};
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
class Imgproc_LSD_ADV: public LSDBase
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-01-17 22:30:29 +01:00
|
|
|
Imgproc_LSD_ADV() { }
|
2013-07-12 23:25:33 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
class Imgproc_LSD_STD: public LSDBase
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-01-17 22:30:29 +01:00
|
|
|
Imgproc_LSD_STD() { }
|
2013-07-12 23:25:33 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
class Imgproc_LSD_NONE: public LSDBase
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-01-17 22:30:29 +01:00
|
|
|
Imgproc_LSD_NONE() { }
|
2013-07-12 23:25:33 +02:00
|
|
|
protected:
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
void LSDBase::GenerateWhiteNoise(Mat& image)
|
|
|
|
{
|
2013-07-14 11:56:22 +02:00
|
|
|
image = Mat(img_size, CV_8UC1);
|
|
|
|
rng.fill(image, RNG::UNIFORM, 0, 256);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LSDBase::GenerateConstColor(Mat& image)
|
|
|
|
{
|
2013-07-14 11:56:22 +02:00
|
|
|
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 256)));
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LSDBase::GenerateLines(Mat& image, const unsigned int numLines)
|
|
|
|
{
|
2013-07-14 11:56:22 +02:00
|
|
|
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);
|
2013-07-21 09:39:24 +02:00
|
|
|
line(image, p1, p2, Scalar(255), 3);
|
2013-07-14 11:56:22 +02:00
|
|
|
}
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LSDBase::GenerateRotatedRect(Mat& image)
|
|
|
|
{
|
2013-07-14 11:56:22 +02:00
|
|
|
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));
|
2013-07-14 13:29:56 +02:00
|
|
|
float angle = rng.uniform(0.f, 360.f);
|
2013-07-14 11:56:22 +02:00
|
|
|
|
|
|
|
Point2f vertices[4];
|
|
|
|
|
|
|
|
RotatedRect rRect = RotatedRect(center, rect_size, angle);
|
|
|
|
|
|
|
|
rRect.points(vertices);
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
2013-07-21 00:31:51 +02:00
|
|
|
line(image, vertices[i], vertices[(i + 1) % 4], Scalar(255), 3);
|
2013-07-14 11:56:22 +02:00
|
|
|
}
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LSDBase::SetUp()
|
|
|
|
{
|
2013-07-14 11:56:22 +02:00
|
|
|
lines.clear();
|
|
|
|
test_image = Mat();
|
2013-07-21 23:55:29 +02:00
|
|
|
rng = RNG(LSD_TEST_SEED);
|
|
|
|
passedtests = 0;
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_ADV, whiteNoise)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
GenerateWhiteNoise(test_image);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-12 23:25:33 +02:00
|
|
|
|
2013-08-09 11:54:16 +02:00
|
|
|
if(40u >= lines.size()) ++passedtests;
|
2013-07-21 23:55:29 +02:00
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_ADV, constColor)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
GenerateConstColor(test_image);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-12 23:25:33 +02:00
|
|
|
|
2013-08-09 11:54:16 +02:00
|
|
|
if(0u == lines.size()) ++passedtests;
|
2013-07-21 23:55:29 +02:00
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_ADV, lines)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
const unsigned int numOfLines = 1;
|
|
|
|
GenerateLines(test_image, numOfLines);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-12 23:25:33 +02:00
|
|
|
|
2013-07-21 23:55:29 +02:00
|
|
|
if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect
|
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_ADV, rotatedRect)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
GenerateRotatedRect(test_image);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_ADV);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-21 00:31:51 +02:00
|
|
|
|
2013-08-09 11:54:16 +02:00
|
|
|
if(2u <= lines.size()) ++passedtests;
|
2013-07-21 23:55:29 +02:00
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_STD, whiteNoise)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
GenerateWhiteNoise(test_image);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-12 23:25:33 +02:00
|
|
|
|
2013-08-09 11:54:16 +02:00
|
|
|
if(50u >= lines.size()) ++passedtests;
|
2013-07-21 23:55:29 +02:00
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_STD, constColor)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
GenerateConstColor(test_image);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-12 23:25:33 +02:00
|
|
|
|
2013-08-09 11:54:16 +02:00
|
|
|
if(0u == lines.size()) ++passedtests;
|
2013-07-21 23:55:29 +02:00
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_STD, lines)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
const unsigned int numOfLines = 1;
|
|
|
|
GenerateLines(test_image, numOfLines);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-12 23:25:33 +02:00
|
|
|
|
2013-07-21 23:55:29 +02:00
|
|
|
if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect
|
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_STD, rotatedRect)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
GenerateRotatedRect(test_image);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-21 00:31:51 +02:00
|
|
|
|
2013-08-09 11:54:16 +02:00
|
|
|
if(4u <= lines.size()) ++passedtests;
|
2013-07-21 23:55:29 +02:00
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_NONE, whiteNoise)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
GenerateWhiteNoise(test_image);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_STD);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-12 23:25:33 +02:00
|
|
|
|
2013-08-09 11:54:16 +02:00
|
|
|
if(50u >= lines.size()) ++passedtests;
|
2013-07-21 23:55:29 +02:00
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_NONE, constColor)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
GenerateConstColor(test_image);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_NONE);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-12 23:25:33 +02:00
|
|
|
|
2013-08-09 11:54:16 +02:00
|
|
|
if(0u == lines.size()) ++passedtests;
|
2013-07-21 23:55:29 +02:00
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_NONE, lines)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
const unsigned int numOfLines = 1;
|
|
|
|
GenerateLines(test_image, numOfLines);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_NONE);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-12 23:25:33 +02:00
|
|
|
|
2013-07-21 23:55:29 +02:00
|
|
|
if(numOfLines * 2 == lines.size()) ++passedtests; // * 2 because of Gibbs effect
|
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|
|
|
|
|
2013-07-21 00:31:51 +02:00
|
|
|
TEST_F(Imgproc_LSD_NONE, rotatedRect)
|
2013-07-12 23:25:33 +02:00
|
|
|
{
|
2013-07-21 23:55:29 +02:00
|
|
|
for (int i = 0; i < EPOCHS; ++i)
|
|
|
|
{
|
|
|
|
GenerateRotatedRect(test_image);
|
2013-09-19 17:06:48 +02:00
|
|
|
Ptr<LineSegmentDetector> detector = createLineSegmentDetector(LSD_REFINE_NONE);
|
2013-07-21 23:55:29 +02:00
|
|
|
detector->detect(test_image, lines);
|
2013-07-21 00:31:51 +02:00
|
|
|
|
2013-08-09 11:54:16 +02:00
|
|
|
if(8u <= lines.size()) ++passedtests;
|
2013-07-21 23:55:29 +02:00
|
|
|
}
|
|
|
|
ASSERT_EQ(EPOCHS, passedtests);
|
2013-07-12 23:25:33 +02:00
|
|
|
}
|