1 #include <iostream>
2 #include <string>
3
4 #include "opencv2/core/core.hpp"
5 #include "opencv2/core/utility.hpp"
6 #include "opencv2/imgproc/imgproc.hpp"
7 #include "opencv2/imgcodecs.hpp"
8 #include "opencv2/highgui/highgui.hpp"
9
10 using namespace std;
11 using namespace cv;
12
main(int argc,char ** argv)13 int main(int argc, char** argv)
14 {
15 std::string in;
16 if (argc != 2)
17 {
18 std::cout << "Usage: lsd_lines [input image]. Now loading ../data/building.jpg" << std::endl;
19 in = "../data/building.jpg";
20 }
21 else
22 {
23 in = argv[1];
24 }
25
26 Mat image = imread(in, IMREAD_GRAYSCALE);
27
28 #if 0
29 Canny(image, image, 50, 200, 3); // Apply canny edge
30 #endif
31
32 // Create and LSD detector with standard or no refinement.
33 #if 1
34 Ptr<LineSegmentDetector> ls = createLineSegmentDetector(LSD_REFINE_STD);
35 #else
36 Ptr<LineSegmentDetector> ls = createLineSegmentDetector(LSD_REFINE_NONE);
37 #endif
38
39 double start = double(getTickCount());
40 vector<Vec4f> lines_std;
41
42 // Detect the lines
43 ls->detect(image, lines_std);
44
45 double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
46 std::cout << "It took " << duration_ms << " ms." << std::endl;
47
48 // Show found lines
49 Mat drawnLines(image);
50 ls->drawSegments(drawnLines, lines_std);
51 imshow("Standard refinement", drawnLines);
52
53 waitKey();
54 return 0;
55 }
56