Ask Your Question

cmc's profile - activity

2020-06-11 18:56:05 -0600 received badge  Popular Question (source)
2014-09-08 04:10:09 -0600 commented question Problems getting point set for convex hull

If I don't remove the contour then there is a risk that a contour may be included in multiple convex hulls.

2014-09-07 16:44:18 -0600 asked a question Problems getting point set for convex hull

I have a function that takes a double (proximity) that determines how far a contour must be from another to be considered close enough to add together. When the contours are added a convex hull is then drawn. When the function takes 2 as its parameter it produces this image: https://i.imgur.com/G5sX6Jc.png.

As you can see from the image something very funky is happening that I cannot figure out. If someone could tell me where I have gone wrong in my code I would be very grateful.

for (size_t i = 0; i < contours.size(); i++)
{
    minDistance = 9999999999999999999;
    for (size_t j = 0; j < contours[i].size(); j++)
    {
        for (size_t a = i + 1; a < contours.size();)
        {
            for (size_t b = 0; b < contours[a].size(); b++)
            {
                euclidean = norm(contours[i][j] - contours[a][b]);
                if (euclidean < minDistance)
                {
                    minDistance = euclidean;
                }
            }
            if (minDistance <= proximity)
            {
                for (size_t q = 0; q < contours[a].size(); q++)
                {
                    contours[i].push_back(contours[a][q]);
                }
                contours.erase(remove(begin(contours), end(contours), contours[a]), contours.end());
            }
            else
            {
                a++;
            }
        }
    }
}
2014-09-07 12:23:00 -0600 commented answer Opencv remove convexity defects from convex Hull

Hmm, yeah. Thanks for tip anyway. Got some reading to do now.

2014-09-07 08:42:54 -0600 commented answer Opencv remove convexity defects from convex Hull

This seems closer to what I would like. Is there a way to achieve this in opencv?

2014-09-06 13:06:16 -0600 asked a question Opencv remove convexity defects from convex Hull

I have an image with a convexHull drawn on it (seen here: http://imgur.com/BPsiIgm). How would I change the grey convex hull line so that, rather than being straight lines to each point in the hull, they conform more to the boundary/contours of the objects within the convex hull?

2014-09-04 04:32:31 -0600 received badge  Scholar (source)
2014-09-04 04:32:30 -0600 received badge  Supporter (source)
2014-09-02 16:09:49 -0600 received badge  Student (source)
2014-09-02 15:59:55 -0600 commented answer Include multiple objects in one contour

Tried convexHull(contour, hull, false); and got a new error: OpenCV Error: Assertion Failed (i < 0) in cv::_InputArray::getMat, file C:\builds\2_4_PackSlave-win64-vc12-shared\opencv\modules\core\src\matrix.cpp, line963.

2014-09-02 15:45:51 -0600 commented answer Include multiple objects in one contour

No, the push_back function seems to work. When I print out the cv::Points in the contour it shows the coordinates from both contours, so they seem to be added together. However, when I attempt to get the convexHull is when the error is caused. This is the code:

vector<Point> hull; convexHull(Mat(contour), hull, false); drawContours(img, hull, 0, Scalar(255), 1, 8, vector<Vec4i>(), 0, Point());

The error occurs on the convexHull line.

2014-09-02 14:45:31 -0600 asked a question OpenCV troubles with convexHull

I have been stuck on a problem for a few days now. I have an image with multiple objects and I would like to group them into a convexHull, kind of like this : https://i.imgur.com/BlyjRbY.png.

I have tried adding the Points of one contour to another using push_back() and using this for the convexHull() method, but to no avail.

I have found a similar question from https://dsp.stackexchange.com/questions/2564/opencv-c-connect-nearby-contours-based-on-distance-between-them. However the code is in python, which I have no clue about nor the time to learn at the moment, and I am using C++.

I really need help on this problem, so if someone could tell me how to achieve my desired solution or how it was done in the python example above but for C++ I would be very appreciative.

2014-09-02 14:28:12 -0600 commented answer Include multiple objects in one contour

I made an image with two objects. I got the two contours then used a for loop to add the points in the second contour to the first using .push_back. This did not work and caused the following error: OpenCV Error: Assertion Failed (0 <= i && i < (int)vv.size()) in cv::_InputArray::getMat, file C:\builds\2_4_PackSlave-win64-vc12-shared\opencv\modules\core\src\matrix.cpp, line977. I'm not sure what I'm doing wrong and have been stuck here for days. I'd appreciate anymore advice you can offer.

2014-09-02 12:12:34 -0600 commented answer Include multiple objects in one contour

How would I "union" the contours?

2014-09-01 16:27:40 -0600 commented answer Include multiple objects in one contour

Thanks for the comment. I already tried using dilate but it was not an acceptable approach as maintaining the edges of the objects vital.

2014-09-01 14:08:33 -0600 asked a question Include multiple objects in one contour

I have a problem and I am not sure how to accomplish it. I am working with binary Mat objects that contain many small objects in them. I have used findContours to generate each objects contour and used contourArea to calculate their area. If the objects are too small they are removed from the image. The next step tests for the distance between contours, if the contours are close enough they should be grouped together when their contour is drawn. The function works up until the objects need to be grouped into one contour. After a lot of reading and trying things out I am unable to figure this out. If any one is able to provide guidance I would appreciate it.

Here is an image for what I would like the output to be:image description

The white blobs are the objects and the red line is my desired contour.