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,
|
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),
|
: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)
|
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;
|
// 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)
|
void LSD::ll_angle(const double& threshold, const unsigned int& n_bins, std::vector<coorlist>& list)
|
||||||
|
@ -13,20 +13,20 @@ public:
|
|||||||
LSDBase() {};
|
LSDBase() {};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Mat test_image;
|
Mat test_image;
|
||||||
vector<Vec4i> lines;
|
vector<Vec4i> lines;
|
||||||
|
|
||||||
void GenerateWhiteNoise(Mat& image);
|
void GenerateWhiteNoise(Mat& image);
|
||||||
void GenerateConstColor(Mat& image);
|
void GenerateConstColor(Mat& image);
|
||||||
void GenerateLines(Mat& image, const unsigned int numLines);
|
void GenerateLines(Mat& image, const unsigned int numLines);
|
||||||
void GenerateRotatedRect(Mat& image);
|
void GenerateRotatedRect(Mat& image);
|
||||||
virtual void SetUp();
|
virtual void SetUp();
|
||||||
};
|
};
|
||||||
|
|
||||||
class LSD_ADV: public LSDBase
|
class LSD_ADV: public LSDBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LSD_ADV() {};
|
LSD_ADV() {};
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -34,7 +34,7 @@ protected:
|
|||||||
class LSD_STD: public LSDBase
|
class LSD_STD: public LSDBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LSD_STD() {};
|
LSD_STD() {};
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -42,171 +42,171 @@ protected:
|
|||||||
class LSD_NONE: public LSDBase
|
class LSD_NONE: public LSDBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LSD_NONE() {};
|
LSD_NONE() {};
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void LSDBase::GenerateWhiteNoise(Mat& image)
|
void LSDBase::GenerateWhiteNoise(Mat& image)
|
||||||
{
|
{
|
||||||
image = Mat(img_size, CV_8UC1);
|
image = Mat(img_size, CV_8UC1);
|
||||||
RNG rng(getTickCount());
|
RNG rng(getTickCount());
|
||||||
rng.fill(image, RNG::UNIFORM, 0, 256);
|
rng.fill(image, RNG::UNIFORM, 0, 256);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LSDBase::GenerateConstColor(Mat& image)
|
void LSDBase::GenerateConstColor(Mat& image)
|
||||||
{
|
{
|
||||||
RNG rng(getTickCount());
|
RNG rng(getTickCount());
|
||||||
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 256)));
|
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 256)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LSDBase::GenerateLines(Mat& image, const unsigned int numLines)
|
void LSDBase::GenerateLines(Mat& image, const unsigned int numLines)
|
||||||
{
|
{
|
||||||
RNG rng(getTickCount());
|
RNG rng(getTickCount());
|
||||||
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128)));
|
image = Mat(img_size, CV_8UC1, Scalar::all(rng.uniform(0, 128)));
|
||||||
|
|
||||||
for(unsigned int i = 0; i < numLines; ++i)
|
for(unsigned int i = 0; i < numLines; ++i)
|
||||||
{
|
{
|
||||||
int y = rng.uniform(10, img_size.width - 10);
|
int y = rng.uniform(10, img_size.width - 10);
|
||||||
Point p1(y, 10);
|
Point p1(y, 10);
|
||||||
Point p2(y, img_size.height - 10);
|
Point p2(y, img_size.height - 10);
|
||||||
line(image, p1, p2, Scalar(255), 1);
|
line(image, p1, p2, Scalar(255), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LSDBase::GenerateRotatedRect(Mat& image)
|
void LSDBase::GenerateRotatedRect(Mat& image)
|
||||||
{
|
{
|
||||||
RNG rng(getTickCount());
|
RNG rng(getTickCount());
|
||||||
image = Mat::zeros(img_size, CV_8UC1);
|
image = Mat::zeros(img_size, CV_8UC1);
|
||||||
|
|
||||||
Point center(rng.uniform(img_size.width/4, img_size.width*3/4),
|
Point center(rng.uniform(img_size.width/4, img_size.width*3/4),
|
||||||
rng.uniform(img_size.height/4, img_size.height*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),
|
Size rect_size(rng.uniform(img_size.width/8, img_size.width/6),
|
||||||
rng.uniform(img_size.height/8, img_size.height/6));
|
rng.uniform(img_size.height/8, img_size.height/6));
|
||||||
float angle = rng.uniform(0, 360);
|
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);
|
rRect.points(vertices);
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
line(image, vertices[i], vertices[(i + 1) % 4], Scalar(255));
|
line(image, vertices[i], vertices[(i + 1) % 4], Scalar(255));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LSDBase::SetUp()
|
void LSDBase::SetUp()
|
||||||
{
|
{
|
||||||
lines.clear();
|
lines.clear();
|
||||||
test_image = Mat();
|
test_image = Mat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST_F(LSD_ADV, whiteNoise)
|
TEST_F(LSD_ADV, whiteNoise)
|
||||||
{
|
{
|
||||||
GenerateWhiteNoise(test_image);
|
GenerateWhiteNoise(test_image);
|
||||||
LSD detector(LSD_REFINE_ADV);
|
LSD detector(LSD_REFINE_ADV);
|
||||||
detector.detect(test_image, lines);
|
detector.detect(test_image, lines);
|
||||||
|
|
||||||
ASSERT_GE((unsigned int)(40), lines.size());
|
ASSERT_GE((unsigned int)(40), lines.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LSD_ADV, constColor)
|
TEST_F(LSD_ADV, constColor)
|
||||||
{
|
{
|
||||||
GenerateConstColor(test_image);
|
GenerateConstColor(test_image);
|
||||||
LSD detector(LSD_REFINE_ADV);
|
LSD detector(LSD_REFINE_ADV);
|
||||||
detector.detect(test_image, lines);
|
detector.detect(test_image, lines);
|
||||||
|
|
||||||
ASSERT_EQ((unsigned int)(0), lines.size());
|
ASSERT_EQ((unsigned int)(0), lines.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LSD_ADV, lines)
|
TEST_F(LSD_ADV, lines)
|
||||||
{
|
{
|
||||||
const unsigned int numOfLines = 3;
|
const unsigned int numOfLines = 3;
|
||||||
GenerateLines(test_image, numOfLines);
|
GenerateLines(test_image, numOfLines);
|
||||||
LSD detector(LSD_REFINE_ADV);
|
LSD detector(LSD_REFINE_ADV);
|
||||||
detector.detect(test_image, lines);
|
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)
|
TEST_F(LSD_ADV, rotatedRect)
|
||||||
{
|
{
|
||||||
GenerateRotatedRect(test_image);
|
GenerateRotatedRect(test_image);
|
||||||
LSD detector(LSD_REFINE_ADV);
|
LSD detector(LSD_REFINE_ADV);
|
||||||
detector.detect(test_image, lines);
|
detector.detect(test_image, lines);
|
||||||
ASSERT_LE((unsigned int)(4), lines.size());
|
ASSERT_LE((unsigned int)(4), lines.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LSD_STD, whiteNoise)
|
TEST_F(LSD_STD, whiteNoise)
|
||||||
{
|
{
|
||||||
GenerateWhiteNoise(test_image);
|
GenerateWhiteNoise(test_image);
|
||||||
LSD detector(LSD_REFINE_STD);
|
LSD detector(LSD_REFINE_STD);
|
||||||
detector.detect(test_image, lines);
|
detector.detect(test_image, lines);
|
||||||
|
|
||||||
ASSERT_GE((unsigned int)(50), lines.size());
|
ASSERT_GE((unsigned int)(50), lines.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LSD_STD, constColor)
|
TEST_F(LSD_STD, constColor)
|
||||||
{
|
{
|
||||||
GenerateConstColor(test_image);
|
GenerateConstColor(test_image);
|
||||||
LSD detector(LSD_REFINE_STD);
|
LSD detector(LSD_REFINE_STD);
|
||||||
detector.detect(test_image, lines);
|
detector.detect(test_image, lines);
|
||||||
|
|
||||||
ASSERT_EQ((unsigned int)(0), lines.size());
|
ASSERT_EQ((unsigned int)(0), lines.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LSD_STD, lines)
|
TEST_F(LSD_STD, lines)
|
||||||
{
|
{
|
||||||
const unsigned int numOfLines = 3; //1
|
const unsigned int numOfLines = 3; //1
|
||||||
GenerateLines(test_image, numOfLines);
|
GenerateLines(test_image, numOfLines);
|
||||||
LSD detector(LSD_REFINE_STD);
|
LSD detector(LSD_REFINE_STD);
|
||||||
detector.detect(test_image, lines);
|
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)
|
TEST_F(LSD_STD, rotatedRect)
|
||||||
{
|
{
|
||||||
GenerateRotatedRect(test_image);
|
GenerateRotatedRect(test_image);
|
||||||
LSD detector(LSD_REFINE_STD);
|
LSD detector(LSD_REFINE_STD);
|
||||||
detector.detect(test_image, lines);
|
detector.detect(test_image, lines);
|
||||||
ASSERT_EQ((unsigned int)(8), lines.size());
|
ASSERT_EQ((unsigned int)(8), lines.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LSD_NONE, whiteNoise)
|
TEST_F(LSD_NONE, whiteNoise)
|
||||||
{
|
{
|
||||||
GenerateWhiteNoise(test_image);
|
GenerateWhiteNoise(test_image);
|
||||||
LSD detector(LSD_REFINE_NONE);
|
LSD detector(LSD_REFINE_NONE);
|
||||||
detector.detect(test_image, lines);
|
detector.detect(test_image, lines);
|
||||||
|
|
||||||
ASSERT_GE((unsigned int)(50), lines.size());
|
ASSERT_GE((unsigned int)(50), lines.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LSD_NONE, constColor)
|
TEST_F(LSD_NONE, constColor)
|
||||||
{
|
{
|
||||||
GenerateConstColor(test_image);
|
GenerateConstColor(test_image);
|
||||||
LSD detector(LSD_REFINE_NONE);
|
LSD detector(LSD_REFINE_NONE);
|
||||||
detector.detect(test_image, lines);
|
detector.detect(test_image, lines);
|
||||||
|
|
||||||
ASSERT_EQ((unsigned int)(0), lines.size());
|
ASSERT_EQ((unsigned int)(0), lines.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(LSD_NONE, lines)
|
TEST_F(LSD_NONE, lines)
|
||||||
{
|
{
|
||||||
const unsigned int numOfLines = 3; //1
|
const unsigned int numOfLines = 3; //1
|
||||||
GenerateLines(test_image, numOfLines);
|
GenerateLines(test_image, numOfLines);
|
||||||
LSD detector(LSD_REFINE_NONE);
|
LSD detector(LSD_REFINE_NONE);
|
||||||
detector.detect(test_image, lines);
|
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)
|
TEST_F(LSD_NONE, rotatedRect)
|
||||||
{
|
{
|
||||||
GenerateRotatedRect(test_image);
|
GenerateRotatedRect(test_image);
|
||||||
LSD detector(LSD_REFINE_NONE);
|
LSD detector(LSD_REFINE_NONE);
|
||||||
detector.detect(test_image, lines);
|
detector.detect(test_image, lines);
|
||||||
ASSERT_EQ((unsigned int)(8), lines.size());
|
ASSERT_EQ((unsigned int)(8), lines.size());
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "opencv2/core/core.hpp"
|
#include "opencv2/core/core.hpp"
|
||||||
|
#include "opencv2/core/utility.hpp"
|
||||||
#include "opencv2/imgproc/imgproc.hpp"
|
#include "opencv2/imgproc/imgproc.hpp"
|
||||||
#include "opencv2/highgui/highgui.hpp"
|
#include "opencv2/highgui/highgui.hpp"
|
||||||
|
|
||||||
@ -10,41 +11,41 @@ using namespace cv;
|
|||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
{
|
{
|
||||||
std::cout << "lsd_lines [input image]" << std::endl;
|
std::cout << "lsd_lines [input image]" << std::endl;
|
||||||
return false;
|
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.
|
// Create and LSD detector with std refinement.
|
||||||
LSD lsd_std(LSD_REFINE_STD);
|
LSD lsd_std(LSD_REFINE_STD);
|
||||||
double start = double(getTickCount());
|
double start = double(getTickCount());
|
||||||
vector<Vec4i> lines_std;
|
vector<Vec4i> lines_std;
|
||||||
lsd_std.detect(image, lines_std);
|
lsd_std.detect(image, lines_std);
|
||||||
double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
|
double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
|
||||||
std::cout << "OpenCV STD (blue) - " << duration_ms << " ms." << std::endl;
|
std::cout << "OpenCV STD (blue) - " << duration_ms << " ms." << std::endl;
|
||||||
|
|
||||||
// Create an LSD detector with no refinement applied.
|
// Create an LSD detector with no refinement applied.
|
||||||
LSD lsd_none(LSD_REFINE_NONE);
|
LSD lsd_none(LSD_REFINE_NONE);
|
||||||
start = double(getTickCount());
|
start = double(getTickCount());
|
||||||
vector<Vec4i> lines_none;
|
vector<Vec4i> lines_none;
|
||||||
lsd_none.detect(image, lines_none);
|
lsd_none.detect(image, lines_none);
|
||||||
duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
|
duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
|
||||||
std::cout << "OpenCV NONE (red)- " << duration_ms << " ms." << std::endl;
|
std::cout << "OpenCV NONE (red)- " << duration_ms << " ms." << std::endl;
|
||||||
std::cout << "Overlapping pixels are shown in purple." << std::endl;
|
std::cout << "Overlapping pixels are shown in purple." << std::endl;
|
||||||
|
|
||||||
Mat difference = Mat::zeros(image.size(), CV_8UC1);
|
Mat difference = Mat::zeros(image.size(), CV_8UC1);
|
||||||
LSD::compareSegments(image.size(), lines_std, lines_none, &difference);
|
LSD::compareSegments(image.size(), lines_std, lines_none, &difference);
|
||||||
imshow("Line difference", difference);
|
imshow("Line difference", difference);
|
||||||
|
|
||||||
Mat drawnLines(image);
|
Mat drawnLines(image);
|
||||||
LSD::drawSegments(drawnLines, lines_std);
|
LSD::drawSegments(drawnLines, lines_std);
|
||||||
imshow("Standard refinement", drawnLines);
|
imshow("Standard refinement", drawnLines);
|
||||||
|
|
||||||
waitKey();
|
waitKey();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user