Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
6fa4834f
Commit
6fa4834f
authored
Jul 21, 2013
by
Daniel Angelov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update on the class. Edited tests and samples.
parent
6f3d6ded
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
108 additions
and
74 deletions
+108
-74
imgproc.hpp
modules/imgproc/include/opencv2/imgproc.hpp
+2
-9
lsd.cpp
modules/imgproc/src/lsd.cpp
+1
-10
test_lsd.cpp
modules/imgproc/test/test_lsd.cpp
+105
-55
No files found.
modules/imgproc/include/opencv2/imgproc.hpp
View file @
6fa4834f
...
@@ -883,18 +883,11 @@ public:
...
@@ -883,18 +883,11 @@ public:
*/
*/
virtual
int
compareSegments
(
const
Size
&
size
,
const
InputArray
lines1
,
const
InputArray
lines2
,
Mat
*
image
=
0
)
=
0
;
virtual
int
compareSegments
(
const
Size
&
size
,
const
InputArray
lines1
,
const
InputArray
lines2
,
Mat
*
image
=
0
)
=
0
;
~
LineSegmentDetector
()
{};
virtual
~
LineSegmentDetector
()
{};
protected
:
LineSegmentDetector
()
{};
};
};
//! Returns a pointer to a LineSegmentDetector class.
//! Returns a pointer to a LineSegmentDetector class.
CV_EXPORTS
Ptr
<
LineSegmentDetector
>
createLineSegmentDetectorSmrtPtr
(
CV_EXPORTS
Ptr
<
LineSegmentDetector
>
createLineSegmentDetectorPtr
(
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
);
CV_EXPORTS
LineSegmentDetector
*
createLineSegmentDetectorPtr
(
int
_refine
=
LSD_REFINE_STD
,
double
_scale
=
0.8
,
int
_refine
=
LSD_REFINE_STD
,
double
_scale
=
0.8
,
double
_sigma_scale
=
0.6
,
double
_quant
=
2.0
,
double
_ang_th
=
22.5
,
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
);
double
_log_eps
=
0
,
double
_density_th
=
0.7
,
int
_n_bins
=
1024
);
...
...
modules/imgproc/src/lsd.cpp
View file @
6fa4834f
...
@@ -389,7 +389,7 @@ private:
...
@@ -389,7 +389,7 @@ private:
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
CV_EXPORTS
Ptr
<
LineSegmentDetector
>
createLineSegmentDetector
Smrt
Ptr
(
CV_EXPORTS
Ptr
<
LineSegmentDetector
>
createLineSegmentDetectorPtr
(
int
_refine
,
double
_scale
,
double
_sigma_scale
,
double
_quant
,
double
_ang_th
,
int
_refine
,
double
_scale
,
double
_sigma_scale
,
double
_quant
,
double
_ang_th
,
double
_log_eps
,
double
_density_th
,
int
_n_bins
)
double
_log_eps
,
double
_density_th
,
int
_n_bins
)
{
{
...
@@ -398,15 +398,6 @@ CV_EXPORTS Ptr<LineSegmentDetector> createLineSegmentDetectorSmrtPtr(
...
@@ -398,15 +398,6 @@ CV_EXPORTS Ptr<LineSegmentDetector> createLineSegmentDetectorSmrtPtr(
_log_eps
,
_density_th
,
_n_bins
));
_log_eps
,
_density_th
,
_n_bins
));
}
}
CV_EXPORTS
LineSegmentDetector
*
createLineSegmentDetectorPtr
(
int
_refine
,
double
_scale
,
double
_sigma_scale
,
double
_quant
,
double
_ang_th
,
double
_log_eps
,
double
_density_th
,
int
_n_bins
)
{
return
new
LineSegmentDetectorImpl
(
_refine
,
_scale
,
_sigma_scale
,
_quant
,
_ang_th
,
_log_eps
,
_density_th
,
_n_bins
);
}
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
LineSegmentDetectorImpl
::
LineSegmentDetectorImpl
(
int
_refine
,
double
_scale
,
double
_sigma_scale
,
double
_quant
,
LineSegmentDetectorImpl
::
LineSegmentDetectorImpl
(
int
_refine
,
double
_scale
,
double
_sigma_scale
,
double
_quant
,
...
...
modules/imgproc/test/test_lsd.cpp
View file @
6fa4834f
...
@@ -6,6 +6,8 @@ using namespace cv;
...
@@ -6,6 +6,8 @@ using namespace cv;
using
namespace
std
;
using
namespace
std
;
const
Size
img_size
(
640
,
480
);
const
Size
img_size
(
640
,
480
);
const
int
LSD_TEST_SEED
=
0x134679
;
const
int
EPOCHS
=
20
;
class
LSDBase
:
public
testing
::
Test
class
LSDBase
:
public
testing
::
Test
{
{
...
@@ -15,6 +17,8 @@ public:
...
@@ -15,6 +17,8 @@ public:
protected
:
protected
:
Mat
test_image
;
Mat
test_image
;
vector
<
Vec4i
>
lines
;
vector
<
Vec4i
>
lines
;
RNG
rng
;
int
passedtests
;
void
GenerateWhiteNoise
(
Mat
&
image
);
void
GenerateWhiteNoise
(
Mat
&
image
);
void
GenerateConstColor
(
Mat
&
image
);
void
GenerateConstColor
(
Mat
&
image
);
...
@@ -50,19 +54,16 @@ protected:
...
@@ -50,19 +54,16 @@ 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
.
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
());
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
());
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
)
...
@@ -76,7 +77,6 @@ void LSDBase::GenerateLines(Mat& image, const unsigned int numLines)
...
@@ -76,7 +77,6 @@ void LSDBase::GenerateLines(Mat& image, const unsigned int numLines)
void
LSDBase
::
GenerateRotatedRect
(
Mat
&
image
)
void
LSDBase
::
GenerateRotatedRect
(
Mat
&
image
)
{
{
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
),
...
@@ -100,116 +100,166 @@ void LSDBase::SetUp()
...
@@ -100,116 +100,166 @@ void LSDBase::SetUp()
{
{
lines
.
clear
();
lines
.
clear
();
test_image
=
Mat
();
test_image
=
Mat
();
rng
=
RNG
(
LSD_TEST_SEED
);
passedtests
=
0
;
}
}
TEST_F
(
Imgproc_LSD_ADV
,
whiteNoise
)
TEST_F
(
Imgproc_LSD_ADV
,
whiteNoise
)
{
{
GenerateWhiteNoise
(
test_image
);
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_ADV
);
{
detector
->
detect
(
test_image
,
lines
);
GenerateWhiteNoise
(
test_image
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_ADV
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_GE
((
unsigned
int
)(
40
),
lines
.
size
());
if
(
uint
(
40
)
>=
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
TEST_F
(
Imgproc_LSD_ADV
,
constColor
)
TEST_F
(
Imgproc_LSD_ADV
,
constColor
)
{
{
GenerateConstColor
(
test_image
);
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_ADV
);
{
detector
->
detect
(
test_image
,
lines
);
GenerateConstColor
(
test_image
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_ADV
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_EQ
((
unsigned
int
)(
0
),
lines
.
size
());
if
(
uint
(
0
)
==
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
TEST_F
(
Imgproc_LSD_ADV
,
lines
)
TEST_F
(
Imgproc_LSD_ADV
,
lines
)
{
{
const
unsigned
int
numOfLines
=
1
;
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
GenerateLines
(
test_image
,
numOfLines
);
{
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_ADV
);
const
unsigned
int
numOfLines
=
1
;
detector
->
detect
(
test_image
,
lines
);
GenerateLines
(
test_image
,
numOfLines
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_ADV
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_EQ
(
numOfLines
*
2
,
lines
.
size
());
// * 2 because of Gibbs effect
if
(
numOfLines
*
2
==
lines
.
size
())
++
passedtests
;
// * 2 because of Gibbs effect
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
TEST_F
(
Imgproc_LSD_ADV
,
rotatedRect
)
TEST_F
(
Imgproc_LSD_ADV
,
rotatedRect
)
{
{
GenerateRotatedRect
(
test_image
);
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_ADV
);
{
detector
->
detect
(
test_image
,
lines
);
GenerateRotatedRect
(
test_image
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_ADV
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_LE
((
unsigned
int
)(
2
),
lines
.
size
());
if
(
uint
(
2
)
<=
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
TEST_F
(
Imgproc_LSD_STD
,
whiteNoise
)
TEST_F
(
Imgproc_LSD_STD
,
whiteNoise
)
{
{
GenerateWhiteNoise
(
test_image
);
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_STD
);
{
detector
->
detect
(
test_image
,
lines
);
GenerateWhiteNoise
(
test_image
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_STD
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_GE
((
unsigned
int
)(
50
),
lines
.
size
());
if
(
uint
(
50
)
>=
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
TEST_F
(
Imgproc_LSD_STD
,
constColor
)
TEST_F
(
Imgproc_LSD_STD
,
constColor
)
{
{
GenerateConstColor
(
test_image
);
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_STD
);
{
detector
->
detect
(
test_image
,
lines
);
GenerateConstColor
(
test_image
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_STD
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_EQ
((
unsigned
int
)(
0
),
lines
.
size
());
if
(
uint
(
0
)
==
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
TEST_F
(
Imgproc_LSD_STD
,
lines
)
TEST_F
(
Imgproc_LSD_STD
,
lines
)
{
{
const
unsigned
int
numOfLines
=
1
;
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
GenerateLines
(
test_image
,
numOfLines
);
{
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_STD
);
const
unsigned
int
numOfLines
=
1
;
detector
->
detect
(
test_image
,
lines
);
GenerateLines
(
test_image
,
numOfLines
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_STD
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_EQ
(
numOfLines
*
2
,
lines
.
size
());
// * 2 because of Gibbs effect
if
(
numOfLines
*
2
==
lines
.
size
())
++
passedtests
;
// * 2 because of Gibbs effect
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
TEST_F
(
Imgproc_LSD_STD
,
rotatedRect
)
TEST_F
(
Imgproc_LSD_STD
,
rotatedRect
)
{
{
GenerateRotatedRect
(
test_image
);
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_STD
);
{
detector
->
detect
(
test_image
,
lines
);
GenerateRotatedRect
(
test_image
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_STD
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_LE
((
unsigned
int
)(
4
),
lines
.
size
());
if
(
uint
(
4
)
<=
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
TEST_F
(
Imgproc_LSD_NONE
,
whiteNoise
)
TEST_F
(
Imgproc_LSD_NONE
,
whiteNoise
)
{
{
GenerateWhiteNoise
(
test_image
);
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_STD
);
{
detector
->
detect
(
test_image
,
lines
);
GenerateWhiteNoise
(
test_image
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_STD
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_GE
((
unsigned
int
)(
50
),
lines
.
size
());
if
(
uint
(
50
)
>=
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
TEST_F
(
Imgproc_LSD_NONE
,
constColor
)
TEST_F
(
Imgproc_LSD_NONE
,
constColor
)
{
{
GenerateConstColor
(
test_image
);
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_NONE
);
{
detector
->
detect
(
test_image
,
lines
);
GenerateConstColor
(
test_image
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_NONE
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_EQ
((
unsigned
int
)(
0
),
lines
.
size
());
if
(
uint
(
0
)
==
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
TEST_F
(
Imgproc_LSD_NONE
,
lines
)
TEST_F
(
Imgproc_LSD_NONE
,
lines
)
{
{
const
unsigned
int
numOfLines
=
1
;
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
GenerateLines
(
test_image
,
numOfLines
);
{
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_NONE
);
const
unsigned
int
numOfLines
=
1
;
detector
->
detect
(
test_image
,
lines
);
GenerateLines
(
test_image
,
numOfLines
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_NONE
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_EQ
(
numOfLines
*
2
,
lines
.
size
());
// * 2 because of Gibbs effect
if
(
numOfLines
*
2
==
lines
.
size
())
++
passedtests
;
// * 2 because of Gibbs effect
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
TEST_F
(
Imgproc_LSD_NONE
,
rotatedRect
)
TEST_F
(
Imgproc_LSD_NONE
,
rotatedRect
)
{
{
GenerateRotatedRect
(
test_image
);
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
LineSegmentDetector
*
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_NONE
);
{
detector
->
detect
(
test_image
,
lines
);
GenerateRotatedRect
(
test_image
);
Ptr
<
LineSegmentDetector
>
detector
=
createLineSegmentDetectorPtr
(
LSD_REFINE_NONE
);
detector
->
detect
(
test_image
,
lines
);
ASSERT_LE
((
unsigned
int
)(
8
),
lines
.
size
());
if
(
uint
(
8
)
<=
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment