Opencvのlsdアルゴリズム

3136 ワード

検出効果はホフ変換より良い
#include
#include
using namespace cv;
using namespace std;
int main()
{
    cout << "hello world" << endl;
    Mat image = imread("E:/Project/DemoV2/56.jpg");
    Mat grayImage;
    cvtColor(image,grayImage,CV_BGR2GRAY);
    // Create and LSD detector with standard or no refinement.
    //Canny(grayImage, grayImage, 50, 200, 3); // Apply canny edge//  canny  
#if 1
    Ptr ls = createLineSegmentDetector(LSD_REFINE_ADV);//    LSD  ,     standard 
#else
    Ptr ls = createLineSegmentDetector(LSD_REFINE_NONE);
#endif
    double start = double(getTickCount());
    vector lines_std;
    // Detect the lines
    ls->detect(grayImage, lines_std);//               lines_std ,4 float  ,         
    for (int i = 0; i < lines_std.size(); i++)
    {
        cout << lines_std[i][0] <<" "<< lines_std[i][1]<<" "
            << lines_std[i][2]<<" "<3]<double duration_ms = (double(getTickCount()) - start) * 1000 / getTickFrequency();
    std::cout << "It took " << duration_ms << " ms." << std::endl;
    // Show found lines
    Mat drawnLines(image);
    ls->drawSegments(drawnLines, lines_std);
    imshow("Standard refinement", drawnLines);
    waitKey(0);
    return 0;
}