OpenCV  4.9.0-dev
Open Source Computer Vision
Loading...
Searching...
No Matches
Public Member Functions | List of all members
cv::ximgproc::FastLineDetector Class Referenceabstract

Class implementing the FLD (Fast Line Detector) algorithm described in [151] . More...

#include <opencv2/ximgproc/fast_line_detector.hpp>

Inheritance diagram for cv::ximgproc::FastLineDetector:
Collaboration diagram for cv::ximgproc::FastLineDetector:

Public Member Functions

virtual ~FastLineDetector ()
 
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 above shown image.
 
virtual void drawSegments (InputOutputArray image, InputArray lines, bool draw_arrow=false, Scalar linecolor=Scalar(0, 0, 255), int linethickness=1)=0
 Draws the line segments on a given image.
 
- Public Member Functions inherited from cv::Algorithm
 Algorithm ()
 
virtual ~Algorithm ()
 
virtual void clear ()
 Clears the algorithm state.
 
virtual bool empty () const
 Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read.
 
virtual String getDefaultName () const
 
virtual void read (const FileNode &fn)
 Reads algorithm parameters from a file storage.
 
virtual void save (const String &filename) const
 
void write (const Ptr< FileStorage > &fs, const String &name=String()) const
 
virtual void write (FileStorage &fs) const
 Stores algorithm parameters in a file storage.
 
void write (FileStorage &fs, const String &name) const
 

Additional Inherited Members

- Static Public Member Functions inherited from cv::Algorithm
template<typename _Tp >
static Ptr< _Tpload (const String &filename, const String &objname=String())
 Loads algorithm from the file.
 
template<typename _Tp >
static Ptr< _TploadFromString (const String &strModel, const String &objname=String())
 Loads algorithm from a String.
 
template<typename _Tp >
static Ptr< _Tpread (const FileNode &fn)
 Reads algorithm from the file node.
 
- Protected Member Functions inherited from cv::Algorithm
void writeFormat (FileStorage &fs) const
 

Detailed Description

Class implementing the FLD (Fast Line Detector) algorithm described in [151] .

#include <iostream>
using namespace std;
using namespace cv;
using namespace cv::ximgproc;
int main(int argc, char** argv)
{
string in;
CommandLineParser parser(argc, argv, "{@input|corridor.jpg|input image}{help h||show help message}");
if (parser.has("help"))
{
parser.printMessage();
return 0;
}
in = samples::findFile(parser.get<string>("@input"));
Mat image = imread(in, IMREAD_GRAYSCALE);
if( image.empty() )
{
return -1;
}
// 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().
// If zero, Canny() is not applied and the input
// image is taken as an edge image.
// do_merge false - If true, incremental merging of segments
// will be performed
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;
// Because of some CPU's power strategy, it seems that the first running of
// an algorithm takes much longer. So here we run the algorithm 10 times
// to see the algorithm's processing time with sufficiently warmed-up
// CPU performance.
for (int run_count = 0; run_count < 5; run_count++) {
double freq = getTickFrequency();
lines.clear();
int64 start = getTickCount();
// Detect the lines with FLD
fld->detect(image, lines);
double duration_ms = double(getTickCount() - start) * 1000 / freq;
cout << "Elapsed time for FLD " << duration_ms << " ms." << endl;
}
// Show found lines with FLD
Mat line_image_fld(image);
fld->drawSegments(line_image_fld, lines);
imshow("FLD result", line_image_fld);
waitKey(1);
ed->params.EdgeDetectionOperator = EdgeDrawing::SOBEL;
ed->params.GradientThresholdValue = 38;
ed->params.AnchorThresholdValue = 8;
vector<Vec6d> ellipses;
for (int run_count = 0; run_count < 5; run_count++) {
double freq = getTickFrequency();
lines.clear();
int64 start = getTickCount();
// Detect edges
//you should call this before detectLines() and detectEllipses()
ed->detectEdges(image);
// Detect lines
ed->detectLines(lines);
double duration_ms = double(getTickCount() - start) * 1000 / freq;
cout << "Elapsed time for EdgeDrawing detectLines " << duration_ms << " ms." << endl;
start = getTickCount();
// Detect circles and ellipses
ed->detectEllipses(ellipses);
duration_ms = double(getTickCount() - start) * 1000 / freq;
cout << "Elapsed time for EdgeDrawing detectEllipses " << duration_ms << " ms." << endl;
}
Mat edge_image_ed = Mat::zeros(image.size(), CV_8UC3);
vector<vector<Point> > segments = ed->getSegments();
for (size_t i = 0; i < segments.size(); i++)
{
const Point* pts = &segments[i][0];
int n = (int)segments[i].size();
polylines(edge_image_ed, &pts, &n, 1, false, Scalar((rand() & 255), (rand() & 255), (rand() & 255)), 1);
}
imshow("EdgeDrawing detected edges", edge_image_ed);
Mat line_image_ed(image);
fld->drawSegments(line_image_ed, lines);
// Draw circles and ellipses
for (size_t i = 0; i < ellipses.size(); i++)
{
Point center((int)ellipses[i][0], (int)ellipses[i][1]);
Size axes((int)ellipses[i][2] + (int)ellipses[i][3], (int)ellipses[i][2] + (int)ellipses[i][4]);
double angle(ellipses[i][5]);
Scalar color = ellipses[i][2] == 0 ? Scalar(255, 255, 0) : Scalar(0, 255, 0);
ellipse(line_image_ed, center, axes, angle, 0, 360, color, 2, LINE_AA);
}
imshow("EdgeDrawing result", line_image_ed);
return 0;
}
Designed for command line parsing.
Definition utility.hpp:820
n-dimensional dense array class
Definition mat.hpp:812
MatSize size
Definition mat.hpp:2160
static CV_NODISCARD_STD MatExpr zeros(int rows, int cols, int type)
Returns a zero array of the specified size and type.
bool empty() const
Returns true if the array has no elements.
Template class for specifying the size of an image or rectangle.
Definition types.hpp:335
@ SOBEL
Definition edge_drawing.hpp:28
Scalar_< double > Scalar
Definition types.hpp:702
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23
int64_t int64
Definition interface.h:61
#define CV_8UC3
Definition interface.h:90
cv::String findFile(const cv::String &relative_path, bool required=true, bool silentMode=false)
Try to find requested data file.
double getTickFrequency()
Returns the number of ticks per second.
int64 getTickCount()
Returns the number of ticks.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
@ IMREAD_GRAYSCALE
If set, always convert image to the single channel grayscale image (codec internal conversion).
Definition imgcodecs.hpp:70
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
void ellipse(InputOutputArray img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a simple or thick elliptic arc or fills an ellipse sector.
void polylines(InputOutputArray img, InputArrayOfArrays pts, bool isClosed, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws several polygonal curves.
@ LINE_AA
antialiased line
Definition imgproc.hpp:899
Ptr< EdgeDrawing > createEdgeDrawing()
Creates a smart pointer to a EdgeDrawing object and initializes it.
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.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3
GOpaque< Size > size(const GMat &src)
Gets dimensions from Mat.
Definition ximgproc.hpp:125
"black box" representation of the file storage associated with a file on disk.
Definition core.hpp:102
STL namespace.

Constructor & Destructor Documentation

◆ ~FastLineDetector()

virtual cv::ximgproc::FastLineDetector::~FastLineDetector ( )
inlinevirtual

Member Function Documentation

◆ detect()

virtual void cv::ximgproc::FastLineDetector::detect ( InputArray  image,
OutputArray  lines 
)
pure virtual
Python:
cv.ximgproc.FastLineDetector.detect(image[, lines]) -> lines

Finds lines in the input image. This is the output of the default parameters of the algorithm on the above shown image.

image
Parameters
imageA 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);
linesA 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.

◆ drawSegments()

virtual void cv::ximgproc::FastLineDetector::drawSegments ( InputOutputArray  image,
InputArray  lines,
bool  draw_arrow = false,
Scalar  linecolor = Scalar(0, 0, 255),
int  linethickness = 1 
)
pure virtual
Python:
cv.ximgproc.FastLineDetector.drawSegments(image, lines[, draw_arrow[, linecolor[, linethickness]]]) -> image

Draws the line segments on a given image.

Parameters
imageThe image, where the lines will be drawn. Should be bigger or equal to the image, where the lines were found.
linesA vector of the lines that needed to be drawn.
draw_arrowIf true, arrow heads will be drawn.
linecolorLine color.
linethicknessLine thickness.

The documentation for this class was generated from the following file: