简体   繁体   中英

Convex hull & Heap corruption with openCV

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.

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM