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