社区首页 >问答首页 >在Opencv findContours函数检测到的等高线中发现了过多的点

在Opencv findContours函数检测到的等高线中发现了过多的点
EN

Stack Overflow用户
提问于 2015-07-22 10:17:47
回答 1查看 1.6K关注 0票数 0

感谢您关注这个问题。

我想用Kinect传感器检测一些移动的物体。这个想法很简单,首先得到每两帧之间的差值图像,然后提取物体的轮廓,最后做进一步的处理。

我试图使用Opencv(2.4.9版)函数findContours来提取轮廓,但问题来了。该函数可以在每个循环中提取约30或40个轮廓,但在每个轮廓中,轮廓中包含约数十亿个点。另外,如果我想使用像drawContoursminAreaRect这样的函数,程序会因为内存错误而崩溃。

以下是相关代码:

代码语言:javascript
代码运行次数:0
复制
    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个点(而其他的都是正常的)

谁能给出一些关于这方面的想法?

EN

回答 1

Stack Overflow用户

发布于 2015-07-23 09:02:22

试着使用approxpolydp来简化你的轮廓。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31560297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档