0

I am currently working on the Intel Perceptual camera with OpenCv. I can get images from the camera, converting them into cv::Mat types, then applying a skin and a depth filter.
Now I want to calculate a convex hull with the "convexHull" function from openCV, but it creates a heap corruption.

Here is the interesting part of the code :

Mat skin = curr.GetSkin() 
vector<Point> points;


for(int i=0; i<skin.rows; i++)
{
    for(int j=0; j<skin.cols; j++)
    {

            if ((int) skin.at<unsigned char>(i,j) > 0 )
            {
                Point pt ;
                pt.x = j ;
                pt.y = i ;
                points.push_back(pt);

            }
        }
    } 
    Mat img(skin.rows, skin.cols, CV_8UC3);
    vector<int> hull;

    convexHull(Mat(points), hull, true);

Where skin is a Matrix that is filled with 255 and 0 values.

NB : This is inside a loop.
Any suggestion ?

PS : I had the same problem using PCL : As soon as I tried to calculate normals, a heap corruption appeared.

Hinkel
  • 23
  • 4
  • Can you provide the piece of code involving the error? – Sga Jun 24 '14 at 07:22
  • Based on the information you've provided, the only possible advice is that you should locate the cause of the heap corruption and fix it. (You're probably either writing outside the bounds of a dynamically allocated array or using a deallocated object.) – molbdnilo Jun 24 '14 at 07:47
  • I just edited my post to add some code. Everything is running fine if I remove the line "convexHull(...)". Thanks for your answers – Hinkel Jun 24 '14 at 07:58
  • pt.x = i ; // should be j ! (so , no wonder ...) also, try to avoid constructs like data[b+17*z-k*29], there's so many ways to f%ckup. use mat.at(r,c) or mat.ptr(r). – berak Jun 24 '14 at 08:02
  • Indeed, I fixed it, thanks. But it didn't remove the heap corruption. – Hinkel Jun 24 '14 at 08:05
  • i bet you got more buffer overruns than that in your code ... – berak Jun 24 '14 at 08:13
  • It's actually running without this line : convexHull(Mat(points), hull, true); Could there still be a buffer overun somewhere else ? – Hinkel Jun 24 '14 at 08:33
  • Are you using Visual Studio (if so, which version?) to compile your code? Are you doing so in Debug or Release mode? – ChileAddict - Intel Jul 24 '14 at 21:26

2 Answers2

0

For your heap corruption issue try the following if you are using a newer VS than VS 2010: go to your project properties in VS201?. Make sure the configuration is set to "All Configurations". Then, under "Configuration Properties->General->Platform Toolset" choose "Visual Studio 2010 (v100)". Open CV uses v100 so if you are using an IDE that does not, there is a compatibility issue.

0

I have the same issue. The memory corruption happened when the vector hull be destroyed.

 vector<int>* hull = new  vector<int>();
 convexHull(Mat(points), *hull, true);
 delete hull; //memory corrupted

If hull adjust its size first, it will solve this problem

vector<int> hull;
hull.resize(points.size());
convexHull(Mat(points), hull, true);
James Wu
  • 21
  • 5