Added LSD accuracy tests.
This commit is contained in:
parent
5350a2f1d9
commit
e51e00ac5f
@ -844,7 +844,7 @@ public:
|
||||
* Create an LSD 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?
|
||||
* NO_REFINE - No refinement applied.
|
||||
* REFINE_NONE - No refinement applied.
|
||||
* REFINE_STD - Standard refinement is applied. E.g. breaking arches into smaller line approximations.
|
||||
* REFINE_ADV - Advanced refinement. Number of false alarms is calculated,
|
||||
* lines are refined through increase of precision, decrement in size, etc.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*///////////////////////////////////////////////////////////////////////////////////////
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
@ -37,13 +37,8 @@
|
||||
// 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 <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <climits>
|
||||
#include <cfloat>
|
||||
#include <vector>
|
||||
|
||||
#include "precomp.hpp"
|
||||
@ -61,13 +56,12 @@ using namespace cv;
|
||||
|
||||
// PI
|
||||
#ifndef M_PI
|
||||
#define M_PI CV_PI // 3.14159265358979323846
|
||||
#define M_PI CV_PI // 3.14159265358979323846
|
||||
#endif
|
||||
#define M_3_2_PI (3 * CV_PI) / 2 // 4.71238898038 // 3/2 pi
|
||||
#define M_2__PI 2 * CV_PI // 6.28318530718 // 2 pi
|
||||
|
||||
// Label for pixels with undefined gradient.
|
||||
#define NOTDEF double(-1024.0)
|
||||
#define NOTDEF double(-1024.0) // Label for pixels with undefined gradient.
|
||||
|
||||
#define NOTUSED 0 // Label for pixels not used in yet.
|
||||
#define USED 1 // Label for pixels already used in detection.
|
||||
|
212
modules/imgproc/test/test_lsd.cpp
Normal file
212
modules/imgproc/test/test_lsd.cpp
Normal file
@ -0,0 +1,212 @@
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
|
||||
const Size img_size(640, 480);
|
||||
|
||||
class LSDBase : public testing::Test
|
||||
{
|
||||
public:
|
||||
LSDBase() {};
|
||||
|
||||
protected:
|
||||
Mat test_image;
|
||||
vector<Vec4i> lines;
|
||||
|
||||
void GenerateWhiteNoise(Mat& image);
|
||||
void GenerateConstColor(Mat& image);
|
||||
void GenerateLines(Mat& image, const unsigned int numLines);
|
||||
void GenerateRotatedRect(Mat& image);
|
||||
virtual void SetUp();
|
||||
};
|
||||
|
||||
class LSD_ADV: public LSDBase
|
||||
{
|
||||
public:
|
||||
LSD_ADV() {};
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
class LSD_STD: public LSDBase
|
||||
{
|
||||
public:
|
||||
LSD_STD() {};
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
class LSD_NONE: public LSDBase
|
||||
{
|
||||
public:
|
||||
LSD_NONE() {};
|
||||
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)
|
||||
{
|
||||
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 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),
|
||||
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, 360);
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
void LSDBase::SetUp()
|
||||
{
|
||||
lines.clear();
|
||||
test_image = Mat();
|
||||
}
|
||||
|
||||
|
||||
TEST_F(LSD_ADV, whiteNoise)
|
||||
{
|
||||
GenerateWhiteNoise(test_image);
|
||||
LSD detector(LSD_REFINE_ADV);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_GE(40, lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_ADV, constColor)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
LSD detector(LSD_REFINE_ADV);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_EQ(0, lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_ADV, lines)
|
||||
{
|
||||
const int numOfLines = 3;
|
||||
GenerateLines(test_image, numOfLines);
|
||||
LSD detector(LSD_REFINE_ADV);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_EQ(numOfLines * 2, lines.size()); // * 2 because of Gibbs effect
|
||||
}
|
||||
|
||||
TEST_F(LSD_ADV, rotatedRect)
|
||||
{
|
||||
GenerateRotatedRect(test_image);
|
||||
LSD detector(LSD_REFINE_ADV);
|
||||
detector.detect(test_image, lines);
|
||||
ASSERT_LE(4, lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_STD, whiteNoise)
|
||||
{
|
||||
GenerateWhiteNoise(test_image);
|
||||
LSD detector(LSD_REFINE_STD);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_GE(50, lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_STD, constColor)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
LSD detector(LSD_REFINE_STD);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_EQ(0, lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_STD, lines)
|
||||
{
|
||||
const int numOfLines = 3; //1
|
||||
GenerateLines(test_image, numOfLines);
|
||||
LSD detector(LSD_REFINE_STD);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_EQ(numOfLines * 2, lines.size()); // * 2 because of Gibbs effect
|
||||
}
|
||||
|
||||
TEST_F(LSD_STD, rotatedRect)
|
||||
{
|
||||
GenerateRotatedRect(test_image);
|
||||
LSD detector(LSD_REFINE_STD);
|
||||
detector.detect(test_image, lines);
|
||||
ASSERT_EQ(8, lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_NONE, whiteNoise)
|
||||
{
|
||||
GenerateWhiteNoise(test_image);
|
||||
LSD detector(LSD_REFINE_NONE);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_GE(50, lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_NONE, constColor)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
LSD detector(LSD_REFINE_NONE);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_EQ(0, lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_NONE, lines)
|
||||
{
|
||||
const int numOfLines = 3; //1
|
||||
GenerateLines(test_image, numOfLines);
|
||||
LSD detector(LSD_REFINE_NONE);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_EQ(numOfLines * 2, lines.size()); // * 2 because of Gibbs effect
|
||||
}
|
||||
|
||||
TEST_F(LSD_NONE, rotatedRect)
|
||||
{
|
||||
GenerateRotatedRect(test_image);
|
||||
LSD detector(LSD_REFINE_NONE);
|
||||
detector.detect(test_image, lines);
|
||||
ASSERT_EQ(8, lines.size());
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user