c++ - OpenCV C++ 如何编写一个与 Matlab 的 bwareaopen 功能相同的函数?

标签 c++ matlab opencv

我正在尝试将 bwareaopen 函数转换为 OpenCV C++ ... 我找到了这段代码,但它无法正常工作。

因此,如果有人解决了这个问题并且可以帮助我,我将非常高兴。

void removeSmallBlobs(cv::Mat& im, double size)
{
    // Only accept CV_8UC1
    if (im.channels() != 1 || im.type() != CV_8U)
        return;

    // Find all contours
    std::vector<std::vector<cv::Point> > contours;
    cv::findContours(im.clone(), contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);

    for (int i = 0; i < contours.size(); i++)
    {
        // Calculate contour area
        double area = cv::contourArea(contours[i]);

        // Remove small objects by drawing the contour with black color
        if (area > 0 && area <= size)
            cv::drawContours(im, contours, i, CV_RGB(0, 0, 0), -1);
    }
}

最佳答案

我觉得你需要开形态学运算。 Here you can see an example .

或在这里查看:How to filter small segments from image in OpenCV?

关于c++ - OpenCV C++ 如何编写一个与 Matlab 的 bwareaopen 功能相同的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23826953/

相关文章:

c++ - UTF-8 和 TinyXML

c++ - 使用 C++ 在 Windows 上发送/接收以太网帧

c++ - SDL2 加载屏幕/线程

matlab - 设置稀疏矩阵多个值的快速方法

matlab - impoly 仅在对数刻度轴上近似正确

opencv - mat.at <short>(x,y)的访问冲突

c++ - 如何从网络摄像头获取原始 mjpg 流

c++ - C++是上下文无关的还是上下文相关的?

arrays - Matlab - 为数组的每个元素运行一个带参数的函数?

image - 沿轮廓计算同质物体