Ask Your Question

PlapPlop's profile - activity

2016-02-08 06:25:31 -0500 commented question Finding intersections of objects in a single contour

Hello Steve, thanks for the suggestion, how do you think I could perform this first step of skeletization? Is there something useful already implemented in OpenCV? I failed to find any so far.

2016-02-04 11:48:35 -0500 received badge  Student (source)
2016-02-04 11:44:32 -0500 asked a question Finding intersections of objects in a single contour

Hello,

I have an image of leaves (seen from above) that can partly recover each other.

http://img11.hostingpics.net/pics/793...

I found the contour of the image (in red on the image) and what I want to do now is to find where two leaves intersect. What I've done so far is to:

  • consider a point with index i in the contour c, say c[i], which has two coordinates x and y,
  • compute the angle of the vector (c[i-1], c[i]) with the half line (x > 0), which I denote ang[i], this returns an angle between 0 and 360,
  • do the previous step for the B angles ang[i], ang[i-1], ang[i-2] and average the result, this gives me the mean direction before c[i],
  • do the same for the B angles ang[i+1], ang[i+2], ang[i+3], etc. and average the result, this gives me the mean direction after c[i],
  • flag (in blue on the image) c[i] as a potential intersection if the difference between the mean direction after and before is greater than a deviation angle D.

I've tried many values of B and D, but due to the different natures of the intersections between leaves, I never manage to recover them all, and uniquely them. Here is an example of output:

http://img11.hostingpics.net/pics/381...

Is something wrong with the method I tried? Is there any other approach less naive and more robust I could try?

Many thanks.

2016-02-04 08:07:05 -0500 received badge  Supporter (source)
2016-02-04 08:07:02 -0500 received badge  Scholar (source)
2016-02-04 08:07:00 -0500 commented answer Why a contour can't always be drawn filled?

Forgot to reply but I tested it and it worked great, thanks a lot.

2016-02-03 10:25:46 -0500 commented question Why a contour can't always be drawn filled?

I edited the question with more details. I should have done that earlier, thanks for the suggestion.

2016-02-03 10:25:00 -0500 received badge  Editor (source)
2016-02-03 03:46:00 -0500 commented question Why a contour can't always be drawn filled?

Thanks for the reply. Actually, I'm not sure I understand what you suggested. I don't really know how drawContours works internally.

2016-02-02 22:41:47 -0500 asked a question Why can't contours always be filled?

Hello,

I find the contours of an object, and I try to fill it with the CV_FILLED option, and sometimes (most of the time), it doesn't fill the contour, and sometimes it does (see attached pictures).

What is this due to and how can I make sure that the contour be filled?

Many thanks,

Heberger image Heberger image

2016-02-02 22:41:47 -0500 asked a question Why a contour can't always be drawn filled?

Hello,

Sometimes when I find the contours of an image, I ask for it to be drawn with CV_FILLED, sometimes (most of the time), it doesn't fill properly the contour, but sometimes it does, why can explain this and how could I make sure it is filled everytime? In blue I plotted the first and the last Points of the contour.

Many thanks

Heberger image

Heberger image

Edit:

A minimal code would be the following:

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;

int main(int argc, char** argv)
{
    int lowThreshold = 50;
    int max_lowThreshold = 100;
    int ratio = 3;
    int kernel_size = 3;
    Mat src1 = imread("/path/to/img1.jpg");
    Mat src2 = imread("/path/to/img2.jpg");
    Mat src_gray1;
    Mat src_gray2;
    cvtColor(src1, src_gray1, CV_BGR2GRAY);
    cvtColor(src2, src_gray2, CV_BGR2GRAY);
    Mat edge1;
    Mat edge2;
    Mat dst1;
    Mat dst2;
    Mat detected_edges1;
    Mat detected_edges2;
    std::vector<std::vector<Point> > contours1, contours2;
    std::vector<Vec4i> hierarchy1, hierarchy2;
    edge1.create(src1.size(), src1.type());
    edge2.create(src2.size(), src2.type());
    dst1.create(src1.size(), src1.type());
    dst2.create(src2.size(), src2.type());
    blur(src_gray1, detected_edges1, Size(3,3));
    blur(src_gray2, detected_edges2, Size(3,3));
    Canny(detected_edges1, detected_edges1, lowThreshold, lowThreshold * ratio, kernel_size);
    Canny(detected_edges2, detected_edges2, lowThreshold, lowThreshold * ratio, kernel_size);
    findContours(detected_edges1, contours1, hierarchy1, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
    findContours(detected_edges2, contours2, hierarchy2, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
    drawContours(edge1, contours1, 0, Scalar(0, 0, 255), CV_FILLED, 8, hierarchy1);
    drawContours(edge2, contours2, 0, Scalar(0, 0, 255), CV_FILLED, 8, hierarchy2);
    imwrite("result1.jpg", edge1);
    imwrite("result2.jpg", edge2);
    return 0;
}

where the files "img1.jpg" and "img2.jpg" can be downloaded from here: http://hpics.li/ecb8b7a http://hpics.li/f1672f0