Introduction:
There is a Cv::ximgproc::fastlinedetector class in the contrib module for the OpenCV3.0 and above versions. Define Location:
Need to download contrib module
OPENCV_CONTRIB/MODULES/XIMGPROC/INCLUDE/OPENCV2/XIMGPROC/FAST_LINE_DETECTOR.HPP
The so-called fast, is relative to the formal module
Cv::imgproc::linesegmentdetectorClass, the speed is faster. The Fastlinedetector class is implemented according to the following paper:
Thesis
outdoor Place recognition in Urban environments using straight Lines
//Download Address:/
http Cvlab.hanyang.ac.kr/~jwlim/files/icra14linerec.pdf
The general principle is:
First, the canny edge detection is applied on the input image, and then the line is found based on the analysis on the canny edge image.
Routines :
This routine compares the running time of the two linear detection operators.
#include <iostream> #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include < string.h> #include <string> #include <dirent.h> #include <unistd.h> #include <vector> # Include <sstream> #include <fstream> #include <sys/io.h> #include <sys/times.h> #include <
iomanip> #include <tuple> #include <cstdlib> using namespace std; #include "opencv2/imgproc.hpp" #include "opencv2/ximgproc.hpp" #include "opencv2/imgcodecs.hpp" #include "opencv2/
HIGHGUI.HPP "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-s Egments shorter than this'll be discarded//distance_threshold 1.41421356-a Point placed from A hypothesis Li NE//segment farther than this'll 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 S Obel//Operator in Canny ()//Do_merge false- If true, incremental merging of segments//would be is perfomred int length_t
Hreshold = 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;
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//times to see each algorithm's processing time with sufficiently warmed-up
CPU performance.
for (int run_count = 0; Run_count < 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:" << setw (Ten) << setiosflags (ios::right) << Setiosflags (ios::fixed) << setprecision (2) << 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:" << setw << setiosflags (ios::right) << Setiosflags (ios::fixed) << setprecision (2) << Duration_ms << "Ms." << Std::end
L }//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; }
Results:
It can be seen that the two algorithms have the same effect, but fld faster.