OpenCV  3.2.0
Open Source Computer Vision
lsd_lines.cpp

An example using the LineSegmentDetector

#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
std::string in;
cv::CommandLineParser parser(argc, argv, "{@input|../data/building.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; }
#if 0
Canny(image, image, 50, 200, 3); // Apply canny edge
#endif
// Create and LSD detector with standard or no refinement.
#if 1
#else
#endif
double start = double(getTickCount());
vector<Vec4f> lines_std;
// Detect the lines
ls->detect(image, lines_std);
double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
std::cout << "It took " << duration_ms << " ms." << std::endl;
// Show found lines
Mat drawnLines(image);
ls->drawSegments(drawnLines, lines_std);
imshow("Standard refinement", drawnLines);
return 0;
}
imgproc.hpp
cv::LSD_REFINE_NONE
@ LSD_REFINE_NONE
No refinement applied.
Definition: imgproc.hpp:479
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.
cv::Canny
void Canny(InputArray image, OutputArray edges, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false)
Finds edges in an image using the Canny algorithm .
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
cv::imread
Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
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::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::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::LSD_REFINE_STD
@ LSD_REFINE_STD
Standard refinement is applied. E.g. breaking arches into smaller straighter line approximations.
Definition: imgproc.hpp:480
cv::CommandLineParser::has
bool has(const String &name) const
Check if field was provided in the command line.