Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
a2582d43
Commit
a2582d43
authored
Dec 12, 2016
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #892 from spacetrain:fast_line_detector
parents
fa8839bb
a7dada15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
362 additions
and
7 deletions
+362
-7
corridor_fld.jpg
modules/ximgproc/doc/pics/corridor_fld.jpg
+0
-0
ximgproc.bib
modules/ximgproc/doc/ximgproc.bib
+9
-0
ximgproc.hpp
modules/ximgproc/include/opencv2/ximgproc.hpp
+8
-7
fast_line_detector.hpp
.../ximgproc/include/opencv2/ximgproc/fast_line_detector.hpp
+81
-0
fld_lines.cpp
modules/ximgproc/samples/fld_lines.cpp
+91
-0
fast_line_detector.cpp
modules/ximgproc/src/fast_line_detector.cpp
+0
-0
test_fld.cpp
modules/ximgproc/test/test_fld.cpp
+173
-0
corridor.jpg
samples/data/corridor.jpg
+0
-0
No files found.
modules/ximgproc/doc/pics/corridor_fld.jpg
0 → 100644
View file @
a2582d43
517 KB
modules/ximgproc/doc/ximgproc.bib
View file @
a2582d43
...
...
@@ -47,6 +47,15 @@
publisher={Springer}
}
@inproceedings{Lee14,
title={Outdoor place recognition in urban environments using straight lines},
author={Lee, Jin Han and Lee, Sehyung and Zhang, Guoxuan and Lim, Jongwoo and Chung, Wan Kyun and Suh, Il Hong},
booktitle={2014 IEEE International Conference on Robotics and Automation (ICRA)},
pages={5550--5557},
year={2014},
organization={IEEE}
}
@inproceedings{Lim2013,
title={Sketch tokens: A learned mid-level representation for contour and object detection},
author={Lim, Joseph J and Zitnick, C Lawrence and Doll{\'a}r, Piotr},
...
...
modules/ximgproc/include/opencv2/ximgproc.hpp
View file @
a2582d43
...
...
@@ -2,26 +2,26 @@
* By downloading, copying, installing or using the software you agree to this license.
* If you do not agree to this license, do not download, install,
* copy or use the software.
*
*
*
*
* License Agreement
* For Open Source Computer Vision Library
* (3 - clause BSD License)
*
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met :
*
*
* *Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and / or other materials provided with the distribution.
*
*
* * Neither the names of the copyright holders nor the names of the contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
*
* This software is provided by the copyright holders and contributors "as is" and
* any express or implied warranties, including, but not limited to, the implied
* warranties of merchantability and fitness for a particular purpose are disclaimed.
...
...
@@ -49,6 +49,7 @@
#include "ximgproc/slic.hpp"
#include "ximgproc/lsc.hpp"
#include "ximgproc/paillou_filter.hpp"
#include "ximgproc/fast_line_detector.hpp"
/** @defgroup ximgproc Extended Image Processing
...
...
modules/ximgproc/include/opencv2/ximgproc/fast_line_detector.hpp
0 → 100644
View file @
a2582d43
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef __OPENCV_FAST_LINE_DETECTOR_HPP__
#define __OPENCV_FAST_LINE_DETECTOR_HPP__
#include <opencv2/core.hpp>
namespace
cv
{
namespace
ximgproc
{
//! @addtogroup ximgproc_feature
//! @{
/** @brief Class implementing the FLD (Fast Line Detector) algorithm described
in @cite Lee14 .
*/
//! @include samples/fld_lines.cpp
class
CV_EXPORTS_W
FastLineDetector
:
public
Algorithm
{
public
:
/** @example fld_lines.cpp
An example using the FastLineDetector
*/
/** @brief Finds lines in the input image.
This is the output of the default parameters of the algorithm on the above
shown image.
![image](pics/corridor_fld.jpg)
@param _image A grayscale (CV_8UC1) input image. If only a roi needs to be
selected, use: `fld_ptr-\>detect(image(roi), lines, ...);
lines += Scalar(roi.x, roi.y, roi.x, roi.y);`
@param _lines A vector of Vec4f elements specifying the beginning
and ending point of a line. Where Vec4f is (x1, y1, x2, y2), point
1 is the start, point 2 - end. Returned lines are directed so that the
brighter side is on their left.
*/
CV_WRAP
virtual
void
detect
(
InputArray
_image
,
OutputArray
_lines
)
=
0
;
/** @brief Draws the line segments on a given image.
@param _image The image, where the lines will be drawn. Should be bigger
or equal to the image, where the lines were found.
@param lines A vector of the lines that needed to be drawn.
@param draw_arrow If true, arrow heads will be drawn.
*/
CV_WRAP
virtual
void
drawSegments
(
InputOutputArray
_image
,
InputArray
lines
,
bool
draw_arrow
=
false
)
=
0
;
virtual
~
FastLineDetector
()
{
}
};
/** @brief Creates a smart pointer to a FastLineDetector object and initializes it
@param _length_threshold 10 - Segment shorter than this will be discarded
@param _distance_threshold 1.41421356 - A point placed from a hypothesis line
segment farther than this will be
regarded as an outlier
@param _canny_th1 50 - First threshold for
hysteresis procedure in Canny()
@param _canny_th2 50 - Second threshold for
hysteresis procedure in Canny()
@param _canny_aperture_size 3 - Aperturesize for the sobel
operator in Canny()
@param _do_merge false - If true, incremental merging of segments
will be perfomred
*/
CV_EXPORTS_W
Ptr
<
FastLineDetector
>
createFastLineDetector
(
int
_length_threshold
=
10
,
float
_distance_threshold
=
1.414213562
f
,
double
_canny_th1
=
50.0
,
double
_canny_th2
=
50.0
,
int
_canny_aperture_size
=
3
,
bool
_do_merge
=
false
);
//! @} ximgproc_feature
}
}
#endif
modules/ximgproc/samples/fld_lines.cpp
0 → 100644
View file @
a2582d43
#include <iostream>
#include "opencv2/imgproc.hpp"
#include "opencv2/ximgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
::
ximgproc
;
int
main
(
int
argc
,
char
**
argv
)
{
std
::
string
in
;
cv
::
CommandLineParser
parser
(
argc
,
argv
,
"{@input|../samples/data/corridor.jpg|input image}{help h||show help message}"
);
if
(
parser
.
has
(
"help"
))
{
parser
.
printMessage
();
return
0
;
}
in
=
parser
.
get
<
string
>
(
"@input"
);
Mat
image
=
imread
(
in
,
IMREAD_GRAYSCALE
);
if
(
image
.
empty
()
)
{
return
-
1
;
}
// Create LSD detector
Ptr
<
LineSegmentDetector
>
lsd
=
createLineSegmentDetector
();
vector
<
Vec4f
>
lines_lsd
;
// Create FLD detector
// Param Default value Description
// length_threshold 10 - Segments shorter than this will be discarded
// distance_threshold 1.41421356 - A point placed from a hypothesis line
// segment farther than this will be
// regarded as an outlier
// canny_th1 50 - First threshold for
// hysteresis procedure in Canny()
// canny_th2 50 - Second threshold for
// hysteresis procedure in Canny()
// canny_aperture_size 3 - Aperturesize for the sobel
// operator in Canny()
// do_merge false - If true, incremental merging of segments
// will be perfomred
int
length_threshold
=
10
;
float
distance_threshold
=
1.41421356
f
;
double
canny_th1
=
50.0
;
double
canny_th2
=
50.0
;
int
canny_aperture_size
=
3
;
bool
do_merge
=
false
;
Ptr
<
FastLineDetector
>
fld
=
createFastLineDetector
(
length_threshold
,
distance_threshold
,
canny_th1
,
canny_th2
,
canny_aperture_size
,
do_merge
);
vector
<
Vec4f
>
lines_fld
;
// Because of some CPU's power strategy, it seems that the first running of
// an algorithm takes much longer. So here we run both of the algorithmes 10
// times to see each algorithm's processing time with sufficiently warmed-up
// CPU performance.
for
(
int
run_count
=
0
;
run_count
<
10
;
run_count
++
)
{
lines_lsd
.
clear
();
int64
start_lsd
=
getTickCount
();
lsd
->
detect
(
image
,
lines_lsd
);
// Detect the lines with LSD
double
freq
=
getTickFrequency
();
double
duration_ms_lsd
=
double
(
getTickCount
()
-
start_lsd
)
*
1000
/
freq
;
std
::
cout
<<
"Elapsed time for LSD: "
<<
duration_ms_lsd
<<
" ms."
<<
std
::
endl
;
lines_fld
.
clear
();
int64
start
=
getTickCount
();
// Detect the lines with FLD
fld
->
detect
(
image
,
lines_fld
);
double
duration_ms
=
double
(
getTickCount
()
-
start
)
*
1000
/
freq
;
std
::
cout
<<
"Ealpsed time for FLD "
<<
duration_ms
<<
" ms."
<<
std
::
endl
;
}
// Show found lines with LSD
Mat
line_image_lsd
(
image
);
lsd
->
drawSegments
(
line_image_lsd
,
lines_lsd
);
imshow
(
"LSD result"
,
line_image_lsd
);
// Show found lines with FLD
Mat
line_image_fld
(
image
);
fld
->
drawSegments
(
line_image_fld
,
lines_fld
);
imshow
(
"FLD result"
,
line_image_fld
);
waitKey
();
return
0
;
}
modules/ximgproc/src/fast_line_detector.cpp
0 → 100644
View file @
a2582d43
This diff is collapsed.
Click to expand it.
modules/ximgproc/test/test_fld.cpp
0 → 100644
View file @
a2582d43
#include "test_precomp.hpp"
#include <vector>
using
namespace
cv
;
using
namespace
cv
::
ximgproc
;
using
namespace
std
;
const
Size
img_size
(
640
,
480
);
const
int
FLD_TEST_SEED
=
0x134679
;
const
int
EPOCHS
=
20
;
class
FLDBase
:
public
testing
::
Test
{
public
:
FLDBase
()
{
}
protected
:
Mat
test_image
;
vector
<
Vec4f
>
lines
;
RNG
rng
;
int
passedtests
;
void
GenerateWhiteNoise
(
Mat
&
image
);
void
GenerateConstColor
(
Mat
&
image
);
void
GenerateLines
(
Mat
&
image
,
const
unsigned
int
numLines
);
void
GenerateBrokenLines
(
Mat
&
image
,
const
unsigned
int
numLines
);
void
GenerateRotatedRect
(
Mat
&
image
);
virtual
void
SetUp
();
};
class
ximgproc_FLD
:
public
FLDBase
{
public
:
ximgproc_FLD
()
{
}
protected
:
};
void
FLDBase
::
GenerateWhiteNoise
(
Mat
&
image
)
{
image
=
Mat
(
img_size
,
CV_8UC1
);
rng
.
fill
(
image
,
RNG
::
UNIFORM
,
0
,
256
);
}
void
FLDBase
::
GenerateConstColor
(
Mat
&
image
)
{
image
=
Mat
(
img_size
,
CV_8UC1
,
Scalar
::
all
(
rng
.
uniform
(
0
,
256
)));
}
void
FLDBase
::
GenerateLines
(
Mat
&
image
,
const
unsigned
int
numLines
)
{
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
),
2
);
}
}
void
FLDBase
::
GenerateBrokenLines
(
Mat
&
image
,
const
unsigned
int
numLines
)
{
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
/
2
);
line
(
image
,
p1
,
p2
,
Scalar
(
255
),
2
);
p1
=
Point2i
(
y
,
img_size
.
height
/
2
+
3
);
p2
=
Point2i
(
y
,
img_size
.
height
-
10
);
line
(
image
,
p1
,
p2
,
Scalar
(
255
),
2
);
}
}
void
FLDBase
::
GenerateRotatedRect
(
Mat
&
image
)
{
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.
f
,
360.
f
);
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
),
3
);
}
}
void
FLDBase
::
SetUp
()
{
lines
.
clear
();
test_image
=
Mat
();
rng
=
RNG
(
FLD_TEST_SEED
);
passedtests
=
0
;
}
TEST_F
(
ximgproc_FLD
,
whiteNoise
)
{
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
{
GenerateWhiteNoise
(
test_image
);
Ptr
<
FastLineDetector
>
detector
=
createFastLineDetector
(
20
);
detector
->
detect
(
test_image
,
lines
);
if
(
40u
>=
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
TEST_F
(
ximgproc_FLD
,
constColor
)
{
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
{
GenerateConstColor
(
test_image
);
Ptr
<
FastLineDetector
>
detector
=
createFastLineDetector
();
detector
->
detect
(
test_image
,
lines
);
if
(
0u
==
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
TEST_F
(
ximgproc_FLD
,
lines
)
{
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
{
const
unsigned
int
numOfLines
=
1
;
GenerateLines
(
test_image
,
numOfLines
);
Ptr
<
FastLineDetector
>
detector
=
createFastLineDetector
();
detector
->
detect
(
test_image
,
lines
);
if
(
numOfLines
*
2
==
lines
.
size
())
++
passedtests
;
// * 2 because of Gibbs effect
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
TEST_F
(
ximgproc_FLD
,
mergeLines
)
{
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
{
const
unsigned
int
numOfLines
=
1
;
GenerateBrokenLines
(
test_image
,
numOfLines
);
Ptr
<
FastLineDetector
>
detector
=
createFastLineDetector
(
10
,
1.414213562
f
,
true
);
detector
->
detect
(
test_image
,
lines
);
if
(
numOfLines
*
2
==
lines
.
size
())
++
passedtests
;
// * 2 because of Gibbs effect
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
TEST_F
(
ximgproc_FLD
,
rotatedRect
)
{
for
(
int
i
=
0
;
i
<
EPOCHS
;
++
i
)
{
GenerateRotatedRect
(
test_image
);
Ptr
<
FastLineDetector
>
detector
=
createFastLineDetector
();
detector
->
detect
(
test_image
,
lines
);
if
(
2u
<=
lines
.
size
())
++
passedtests
;
}
ASSERT_EQ
(
EPOCHS
,
passedtests
);
}
samples/data/corridor.jpg
0 → 100644
View file @
a2582d43
225 KB
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