Convex hull & Heap corruption with openCV

Convex hull & Heap corruption with openCV

本文关键字:with openCV corruption Heap hull Convex      更新时间:2023-10-16

我目前正在使用OpenCv开发英特尔感知相机。我可以从相机中获取图像,将它们转换为cv::Mat类型,然后应用皮肤和深度过滤器。现在我想用openCV中的"convexHull"函数来计算凸壳,但它会产生堆损坏。

下面是代码中有趣的部分:
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);

其中skin是一个填充了255和0值的矩阵。

注意:这是在循环中。
有什么建议吗?

PS:我在使用PCL时遇到了同样的问题:当我试图计算法线时,出现了堆损坏。

对于堆损坏问题,如果您使用比VS 2010更新的VS,请尝试以下操作:转到VS201中的项目属性?确保配置设置为"所有配置"。然后,在"配置属性->通用->平台工具集"下选择"Visual Studio 2010 (v100)"。Open CV使用v100,因此如果您使用的IDE不支持v100,则存在兼容性问题。

我有同样的问题。内存损坏发生在矢量船体被摧毁的时候。

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

如果船体先调整尺寸,就能解决这个问题

vector<int> hull;
hull.resize(points.size());
convexHull(Mat(points), hull, true);