Ask Your Question

Revision history [back]

Using 0.8 instead of 3 :

#include <opencv2/opencv.hpp> 
#include <opencv2/ximgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;


int main(int argc, char **argv)
{
    Mat select = imread("line.png", IMREAD_GRAYSCALE);
    Mat thinning_select;
    ximgproc::thinning(select, thinning_select, ximgproc::THINNING_ZHANGSUEN);
    Mat select_float;
    distanceTransform(select, select_float, DIST_C, 5);
    Mat img;
    // Quantize the hue to 30 levels
    // and the saturation to 32 levels
    int bins = 256;
    int histSize[] = { bins};
    float range[] = { 0, 256 };
    const float* ranges[] = { range};
    // we compute the histogram from the 0-th and 1-st channels
    int channels[] = { 0 };
    Mat hist;
    calcHist(&select_float, 1, channels, thinning_select, hist, 1, histSize, ranges,true,false);
    double tailleSquelette = countNonZero(thinning_select);
    double ratio = 0;
    int i = 0;
    while (ratio < tailleSquelette*0.8 && i<hist.rows)
    {
        ratio += hist.at<float>(i, 0);
        i++;
    }


    Mat mask = select_float <= i;

    imshow("No line", mask);
    waitKey(0);
return 0;
}