我目前正在研究使用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值的Matrix。
注意:这是一个循环。
有什么建议吗?
PS:我在使用PCL时遇到了同样的问题:一旦我尝试计算法线,就会出现堆损坏。
答案 0 :(得分:0)
对于堆损坏问题,如果您使用的是比VS 2010更新的VS,请尝试以下操作:转到VS201中的项目属性?确保配置设置为“所有配置”。然后,在“Configuration Properties-&gt; General-&gt; Platform Toolset”下选择“Visual Studio 2010(v100)”。 Open CV使用v100,因此如果您使用的是IDE,则存在兼容性问题。
答案 1 :(得分:0)
我有同样的问题。当矢量外壳被破坏时发生了内存损坏。
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);