感谢您关注这个问题。
我想用Kinect传感器检测一些移动的物体。这个想法很简单,首先得到每两帧之间的差值图像,然后提取物体的轮廓,最后做进一步的处理。
我试图使用Opencv(2.4.9版)函数findContours
来提取轮廓,但问题来了。该函数可以在每个循环中提取约30或40个轮廓,但在每个轮廓中,轮廓中包含约数十亿个点。另外,如果我想使用像drawContours
或minAreaRect
这样的函数,程序会因为内存错误而崩溃。
以下是相关代码:
findContours(Black, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE,
Point(0, 0));
//1. If nothing has entered the camera frame, skip
if(contours.size()==0)
{
//cout<<"NoContours ";
continue;
}
//2. Only save the maximum contour(index) as the result
max_index = 0;
for (size_t i = 1; i < contours.size(); i++)
{
//cout << " Num of Points: " << contours[i].size() << endl;
if(contours[max_index].size() < contours[i].size())
{
max_index = int(i);
}
}
//3. If the maximum contour's size is smaller than 5, regard it as noise
//cout << contours[max_index].size() << endl;
if(contours[max_index].size() < 5)
{
continue;
}
//find a smallest RotatedRect to express the contour(error happen)
minRect = minAreaRect(Mat(contours[max_index]));
RotatedRect minEllipse = fitEllipse(contours[max_index]);
当它运行到最后两行代码时,将发生错误。我认为主要的原因是findContours
函数在每个轮廓中发现了太多的点,这导致内存不足。
我现在不能发送图像,但是findContours
函数在至少50%的等高线上找到了大约4294966890个点(而其他的都是正常的)
谁能给出一些关于这方面的想法?
发布于 2015-07-23 09:02:22
试着使用approxpolydp来简化你的轮廓。
https://stackoverflow.com/questions/31560297
复制相似问题