extract the midrib of a leaf

asked 2020-02-26 09:19:32 -0500

SylvainArd gravatar image

updated 2020-02-26 09:20:23 -0500

Hi I am trying to extract the midrib of a leaf Here is my code :

int main( int argc, char** argv )
{
    src = imread(  "foliole1.jpg" , IMREAD_COLOR ); // Load an image

    Mat drawing = src.clone();

    Mat bgr[3];   //destination array
    split(src,bgr);//split source
    src_gray=bgr[1];//green channel
    imwrite("gray.bmp",src_gray);

    Mat grayBlurred;
    blur( src_gray, grayBlurred, Size(4,4) );

    Mat detected_edges_canny;
    Canny( grayBlurred, detected_edges_canny,50,100,3);
    imwrite("grayBlurred.jpg",grayBlurred);
    imwrite("detected_edges_canny.jpg",detected_edges_canny);
    vector<Vec4i> lines;
    HoughLinesP(detected_edges_canny, lines, 1, CV_PI/360, 30,100, 20);
    double maxLength=0;
    bool found;
    Segment midRib;
    Mat segments=src.clone();
    for( size_t i = 0; i < lines.size(); i++ )
    {
        Vec4i l = lines[i];
        Segment S=Segment(Point(l[0], l[1]), Point(l[2], l[3]));
        S.draw(segments,2,Scalar(0,0,255));
        if (S.getLength()>maxLength)
        {
            midRib=S;
            found=true;
            maxLength=S.getLength();
        }
    }
    imwrite("segments.jpg",segments);
    Mat midrib=src.clone();
    midRib.draw(midrib,2,Scalar(0,0,255));
    imwrite("midrib.jpg",midrib);
}

and the images are at : http://sylvain-ard.fr/temp/ like you can see it doen't works. please help me thank you :) bye

edit retag flag offensive close merge delete