gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 22:58:28 25 4
gpt4 key购买 nike

我正在尝试将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com