程式語言 - OpenCV - Image Processing - Fast Line Detector



參考資訊:
https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

main.cpp

#include <iostream>
#include <opencv2/imgproc.hpp>
#include <opencv2/ximgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv;
using namespace cv::ximgproc;

int main(int argc, char **argv)
{
    Mat image = imread("main.jpg", IMREAD_GRAYSCALE);
    if (image.empty())
    {
        printf("failed to load image\n");
        return -1;
    }

    Ptr<FastLineDetector> fld = createFastLineDetector();
    vector<Vec4f> lines_fld;
    lines_fld.clear();
    fld->detect(image, lines_fld);

    Mat line_image_fld(image);
    fld->drawSegments(line_image_fld, lines_fld);
    imshow("FLD result", line_image_fld);
    waitKey();
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project(main)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})

編譯並且執行

$ cmake .
$ make
$ ./main

完成