OpenCV  3.2.0
Open Source Computer Vision
fld_lines.cpp

An example using the FastLineDetector

#include <iostream>
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
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.41421356f;
double canny_th1 = 50.0;
double canny_th2 = 50.0;
int canny_aperture_size = 3;
bool do_merge = false;
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);
return 0;
}
imgproc.hpp
cv::CommandLineParser::get
T get(const String &name, bool space_delete=true) const
Access arguments by name.
Definition: utility.hpp:801
cv::waitKey
int waitKey(int delay=0)
Waits for a pressed key.
highgui.hpp
cv::LineSegmentDetector::drawSegments
virtual void drawSegments(InputOutputArray _image, InputArray lines)=0
Draws the line segments on a given image.
cv::IMREAD_GRAYSCALE
@ IMREAD_GRAYSCALE
If set, always convert image to the single channel grayscale image.
Definition: imgcodecs.hpp:66
int64
int64_t int64
Definition: interface.h:57
cv::ximgproc::FastLineDetector::drawSegments
virtual void drawSegments(InputOutputArray _image, InputArray lines, bool draw_arrow=false)=0
Draws the line segments on a given image.
cv::ximgproc::FastLineDetector::detect
virtual void detect(InputArray _image, OutputArray _lines)=0
Finds lines in the input image. This is the output of the default parameters of the algorithm on the ...
cv::imread
Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
ximgproc.hpp
imgcodecs.hpp
cv::Ptr
Template class for smart pointers with shared ownership.
Definition: cvstd.hpp:281
cv::getTickCount
int64 getTickCount()
Returns the number of ticks.
cv::ximgproc::createFastLineDetector
Ptr< FastLineDetector > createFastLineDetector(int _length_threshold=10, float _distance_threshold=1.414213562f, double _canny_th1=50.0, double _canny_th2=50.0, int _canny_aperture_size=3, bool _do_merge=false)
Creates a smart pointer to a FastLineDetector object and initializes it.
cv::LineSegmentDetector::detect
virtual void detect(InputArray _image, OutputArray _lines, OutputArray width=noArray(), OutputArray prec=noArray(), OutputArray nfa=noArray())=0
Finds lines in the input image.
cv::imshow
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
cv::ximgproc
Definition: deriche_filter.hpp:44
cv::getTickFrequency
double getTickFrequency()
Returns the number of ticks per second.
cv::Mat
n-dimensional dense array class
Definition: mat.hpp:741
cv::CommandLineParser
Designed for command line parsing.
Definition: utility.hpp:735
cv
Definition: affine.hpp:52
cv::CommandLineParser::printMessage
void printMessage() const
Print help message.
cv::createLineSegmentDetector
Ptr< LineSegmentDetector > createLineSegmentDetector(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)
Creates a smart pointer to a LineSegmentDetector object and initializes it.
cv::CommandLineParser::has
bool has(const String &name) const
Check if field was provided in the command line.