lsd_lines.cpp 1.32 KB
Newer Older
1 2 3 4
#include <iostream>
#include <string>

#include "opencv2/core/core.hpp"
5
#include "opencv2/core/utility.hpp"
6
#include "opencv2/imgproc/imgproc.hpp"
7
#include "opencv2/imgcodecs.hpp"
8 9 10 11 12 13 14
#include "opencv2/highgui/highgui.hpp"

using namespace std;
using namespace cv;

int main(int argc, char** argv)
{
15
    std::string in;
16 17
    if (argc != 2)
    {
Dmitriy Anisimov's avatar
Dmitriy Anisimov committed
18 19
        std::cout << "Usage: lsd_lines [input image]. Now loading ../data/building.jpg" << std::endl;
        in = "../data/building.jpg";
20 21 22 23
    }
    else
    {
        in = argv[1];
24 25 26 27
    }

    Mat image = imread(in, IMREAD_GRAYSCALE);

28 29 30 31 32 33
#if 0
    Canny(image, image, 50, 200, 3); // Apply canny edge
#endif

    // Create and LSD detector with standard or no refinement.
#if 1
34
    Ptr<LineSegmentDetector> ls = createLineSegmentDetector(LSD_REFINE_STD);
35
#else
36
    Ptr<LineSegmentDetector> ls = createLineSegmentDetector(LSD_REFINE_NONE);
37 38
#endif

39
    double start = double(getTickCount());
40
    vector<Vec4f> lines_std;
41

42 43
    // Detect the lines
    ls->detect(image, lines_std);
44

45 46
    double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
    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 52 53 54
    imshow("Standard refinement", drawnLines);

    waitKey();
    return 0;
55
}