【发布时间】:2011-12-22 01:12:09
【问题描述】:
我是 OpenCV 的新手,在使用它时遇到了一些问题。
目前我正在研究二进制分区树 (BPT) 算法。基本上我需要将图像分成许多区域,并基于一些参数。 2 个区域将合并形成 1 个新区域,由这 2 个区域组成。
我设法通过使用 cvWatershed 获得了初始区域。我还创建了一个向量来存储这些区域,每个区域都在 1 个向量块中。但是,当我尝试将轮廓信息移动到向量中时,会出现内存泄漏。它说,内存泄漏。
for (int h = 0; h <compCount; h++) // compCount - Amount of regions found through cvWaterShed
{
cvZero(WSRegion); // clears out an image, used for painting
Region.push_back(EmptyNode); // create an empty vector slot
CvScalar RegionColor = colorTab[h]; // the color of the region in watershed
for (int i = 0; i <WSOut->height; i++)
{
for (int j = 0; j <WSOut->width; j++)
{
CvScalar s = cvGet2D(WSOut, i, j); // get pixel color in watershed image
if (s.val[0] == RegionColor.val[0] && s.val[1] == RegionColor.val[1] && s.val[2] == RegionColor.val[2])
{
cvSet2D(WSRegion, i, j, cvScalarAll(255)); // paint the pixel to white if it has the same color with the region[h]
}
}
}
MemStorage = cvCreateMemStorage(); // create memory storage
cvFindContours(WSRegion, MemStorage, &contours, sizeof(CvContour), CV_RETR_LIST);
Region[h].RegionContour = cvCloneSeq(contours); // clone and store in vector Region[h]
Region[h].RegionContour->h_next = NULL;
}
有什么办法可以解决这个问题吗?或者有什么替代方法我不需要为每个区域向量创建一个新的内存存储?提前谢谢你
【问题讨论】:
标签: opencv