Added needed header, changed macro name.
This commit is contained in:
parent
3350533f48
commit
22c8010b2d
@ -160,7 +160,7 @@ inline double log_gamma_lanczos(const double& x)
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LSD::LSD(lsd_refine_lvl _refine, double _scale, double _sigma_scale, double _quant,
|
||||
double _ang_th, double _log_eps, double _density_th, int _n_bins)
|
||||
double _ang_th, double _log_eps, double _density_th, int _n_bins)
|
||||
:SCALE(_scale), doRefine(_refine), SIGMA_SCALE(_sigma_scale), QUANT(_quant),
|
||||
ANG_TH(_ang_th), LOG_EPS(_log_eps), DENSITY_TH(_density_th), N_BINS(_n_bins)
|
||||
{
|
||||
@ -308,11 +308,8 @@ void LSD::flsd(std::vector<Vec4i>& lines,
|
||||
// {
|
||||
// region.data[reg[i].x + reg[i].y * width] = ls_count;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void LSD::ll_angle(const double& threshold, const unsigned int& n_bins, std::vector<coorlist>& list)
|
||||
|
@ -13,20 +13,20 @@ public:
|
||||
LSDBase() {};
|
||||
|
||||
protected:
|
||||
Mat test_image;
|
||||
vector<Vec4i> lines;
|
||||
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();
|
||||
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() {};
|
||||
LSD_ADV() {};
|
||||
protected:
|
||||
|
||||
};
|
||||
@ -34,7 +34,7 @@ protected:
|
||||
class LSD_STD: public LSDBase
|
||||
{
|
||||
public:
|
||||
LSD_STD() {};
|
||||
LSD_STD() {};
|
||||
protected:
|
||||
|
||||
};
|
||||
@ -42,171 +42,171 @@ protected:
|
||||
class LSD_NONE: public LSDBase
|
||||
{
|
||||
public:
|
||||
LSD_NONE() {};
|
||||
LSD_NONE() {};
|
||||
protected:
|
||||
|
||||
};
|
||||
|
||||
void LSDBase::GenerateWhiteNoise(Mat& image)
|
||||
{
|
||||
image = Mat(img_size, CV_8UC1);
|
||||
RNG rng(getTickCount());
|
||||
rng.fill(image, RNG::UNIFORM, 0, 256);
|
||||
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)));
|
||||
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)));
|
||||
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);
|
||||
}
|
||||
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);
|
||||
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);
|
||||
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];
|
||||
Point2f vertices[4];
|
||||
|
||||
RotatedRect rRect = RotatedRect(center, rect_size, angle);
|
||||
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));
|
||||
}
|
||||
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();
|
||||
lines.clear();
|
||||
test_image = Mat();
|
||||
}
|
||||
|
||||
|
||||
TEST_F(LSD_ADV, whiteNoise)
|
||||
{
|
||||
GenerateWhiteNoise(test_image);
|
||||
LSD detector(LSD_REFINE_ADV);
|
||||
detector.detect(test_image, lines);
|
||||
GenerateWhiteNoise(test_image);
|
||||
LSD detector(LSD_REFINE_ADV);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_GE((unsigned int)(40), lines.size());
|
||||
ASSERT_GE((unsigned int)(40), lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_ADV, constColor)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
LSD detector(LSD_REFINE_ADV);
|
||||
detector.detect(test_image, lines);
|
||||
GenerateConstColor(test_image);
|
||||
LSD detector(LSD_REFINE_ADV);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_EQ((unsigned int)(0), lines.size());
|
||||
ASSERT_EQ((unsigned int)(0), lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_ADV, lines)
|
||||
{
|
||||
const unsigned int numOfLines = 3;
|
||||
GenerateLines(test_image, numOfLines);
|
||||
LSD detector(LSD_REFINE_ADV);
|
||||
detector.detect(test_image, lines);
|
||||
const unsigned 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
|
||||
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((unsigned int)(4), lines.size());
|
||||
GenerateRotatedRect(test_image);
|
||||
LSD detector(LSD_REFINE_ADV);
|
||||
detector.detect(test_image, lines);
|
||||
ASSERT_LE((unsigned int)(4), lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_STD, whiteNoise)
|
||||
{
|
||||
GenerateWhiteNoise(test_image);
|
||||
LSD detector(LSD_REFINE_STD);
|
||||
detector.detect(test_image, lines);
|
||||
GenerateWhiteNoise(test_image);
|
||||
LSD detector(LSD_REFINE_STD);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_GE((unsigned int)(50), lines.size());
|
||||
ASSERT_GE((unsigned int)(50), lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_STD, constColor)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
LSD detector(LSD_REFINE_STD);
|
||||
detector.detect(test_image, lines);
|
||||
GenerateConstColor(test_image);
|
||||
LSD detector(LSD_REFINE_STD);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_EQ((unsigned int)(0), lines.size());
|
||||
ASSERT_EQ((unsigned int)(0), lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_STD, lines)
|
||||
{
|
||||
const unsigned int numOfLines = 3; //1
|
||||
GenerateLines(test_image, numOfLines);
|
||||
LSD detector(LSD_REFINE_STD);
|
||||
detector.detect(test_image, lines);
|
||||
const unsigned 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
|
||||
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((unsigned int)(8), lines.size());
|
||||
GenerateRotatedRect(test_image);
|
||||
LSD detector(LSD_REFINE_STD);
|
||||
detector.detect(test_image, lines);
|
||||
ASSERT_EQ((unsigned int)(8), lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_NONE, whiteNoise)
|
||||
{
|
||||
GenerateWhiteNoise(test_image);
|
||||
LSD detector(LSD_REFINE_NONE);
|
||||
detector.detect(test_image, lines);
|
||||
GenerateWhiteNoise(test_image);
|
||||
LSD detector(LSD_REFINE_NONE);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_GE((unsigned int)(50), lines.size());
|
||||
ASSERT_GE((unsigned int)(50), lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_NONE, constColor)
|
||||
{
|
||||
GenerateConstColor(test_image);
|
||||
LSD detector(LSD_REFINE_NONE);
|
||||
detector.detect(test_image, lines);
|
||||
GenerateConstColor(test_image);
|
||||
LSD detector(LSD_REFINE_NONE);
|
||||
detector.detect(test_image, lines);
|
||||
|
||||
ASSERT_EQ((unsigned int)(0), lines.size());
|
||||
ASSERT_EQ((unsigned int)(0), lines.size());
|
||||
}
|
||||
|
||||
TEST_F(LSD_NONE, lines)
|
||||
{
|
||||
const unsigned int numOfLines = 3; //1
|
||||
GenerateLines(test_image, numOfLines);
|
||||
LSD detector(LSD_REFINE_NONE);
|
||||
detector.detect(test_image, lines);
|
||||
const unsigned 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
|
||||
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((unsigned int)(8), lines.size());
|
||||
GenerateRotatedRect(test_image);
|
||||
LSD detector(LSD_REFINE_NONE);
|
||||
detector.detect(test_image, lines);
|
||||
ASSERT_EQ((unsigned int)(8), lines.size());
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
@ -10,41 +11,41 @@ using namespace cv;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2)
|
||||
{
|
||||
std::cout << "lsd_lines [input image]" << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (argc != 2)
|
||||
{
|
||||
std::cout << "lsd_lines [input image]" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string in = argv[1];
|
||||
std::string in = argv[1];
|
||||
|
||||
Mat image = imread(in, CV_LOAD_IMAGE_GRAYSCALE);
|
||||
Mat image = imread(in, IMREAD_GRAYSCALE);
|
||||
|
||||
// Create and LSD detector with std refinement.
|
||||
LSD lsd_std(LSD_REFINE_STD);
|
||||
double start = double(getTickCount());
|
||||
vector<Vec4i> lines_std;
|
||||
lsd_std.detect(image, lines_std);
|
||||
double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
|
||||
std::cout << "OpenCV STD (blue) - " << duration_ms << " ms." << std::endl;
|
||||
// Create and LSD detector with std refinement.
|
||||
LSD lsd_std(LSD_REFINE_STD);
|
||||
double start = double(getTickCount());
|
||||
vector<Vec4i> lines_std;
|
||||
lsd_std.detect(image, lines_std);
|
||||
double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
|
||||
std::cout << "OpenCV STD (blue) - " << duration_ms << " ms." << std::endl;
|
||||
|
||||
// Create an LSD detector with no refinement applied.
|
||||
LSD lsd_none(LSD_REFINE_NONE);
|
||||
start = double(getTickCount());
|
||||
vector<Vec4i> lines_none;
|
||||
lsd_none.detect(image, lines_none);
|
||||
duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
|
||||
std::cout << "OpenCV NONE (red)- " << duration_ms << " ms." << std::endl;
|
||||
std::cout << "Overlapping pixels are shown in purple." << std::endl;
|
||||
// Create an LSD detector with no refinement applied.
|
||||
LSD lsd_none(LSD_REFINE_NONE);
|
||||
start = double(getTickCount());
|
||||
vector<Vec4i> lines_none;
|
||||
lsd_none.detect(image, lines_none);
|
||||
duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
|
||||
std::cout << "OpenCV NONE (red)- " << duration_ms << " ms." << std::endl;
|
||||
std::cout << "Overlapping pixels are shown in purple." << std::endl;
|
||||
|
||||
Mat difference = Mat::zeros(image.size(), CV_8UC1);
|
||||
LSD::compareSegments(image.size(), lines_std, lines_none, &difference);
|
||||
imshow("Line difference", difference);
|
||||
Mat difference = Mat::zeros(image.size(), CV_8UC1);
|
||||
LSD::compareSegments(image.size(), lines_std, lines_none, &difference);
|
||||
imshow("Line difference", difference);
|
||||
|
||||
Mat drawnLines(image);
|
||||
LSD::drawSegments(drawnLines, lines_std);
|
||||
imshow("Standard refinement", drawnLines);
|
||||
Mat drawnLines(image);
|
||||
LSD::drawSegments(drawnLines, lines_std);
|
||||
imshow("Standard refinement", drawnLines);
|
||||
|
||||
waitKey();
|
||||
return 0;
|
||||
waitKey();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user