当前位置:网站首页>光条提取中的连通域筛除
光条提取中的连通域筛除
2022-08-04 05:29:00 【视觉菜鸟Leonardo】
在线结构光三维重建中,对于得到的激光光条需要先进行图像处理,其中包括使用连通域筛除来去除图片中出光条以外的杂志。
连通域筛除,步骤为
搜索图像的连通区轮廓->遍历各个连通区->基于阈值删除面积较小的连通区
使用findContours函数来寻找轮廓,使用const_iterator迭代器来遍历连通区轮廓,使用boundingRect计算轮廓面积,设置面积阈值,轮廓面积比阈值小,则灰度值调为0,反之不变。
连通区域筛除程序:
/**
* @brief Clear_MicroConnected_Areas 清除微小面积连通区函数
* @param src 输入图像矩阵
* @param dst 输出结果
* @return min_area 设定的最小面积清除阈值
*/
void Clear_MicroConnected_Areas(cv::Mat src, cv::Mat &dst, double min_area)
{
// 备份复制
dst = src.clone();
std::vector<std::vector<cv::Point> > contours; // 创建轮廓容器
std::vector<cv::Vec4i> hierarchy;
// 寻找轮廓的函数
// 第四个参数CV_RETR_EXTERNAL,表示寻找最外围轮廓
// 第五个参数CV_CHAIN_APPROX_NONE,表示保存物体边界上所有连续的轮廓点到contours向量内
cv::findContours(src, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_NONE, cv::Point());
if (!contours.empty() && !hierarchy.empty())
{
std::vector<std::vector<cv::Point> >::const_iterator itc = contours.begin();
// 遍历所有轮廓
while (itc != contours.end())
{
// 定位当前轮廓所在位置
cv::Rect rect = cv::boundingRect(cv::Mat(*itc));
// contourArea函数计算连通区面积
double area = contourArea(*itc);
// 若面积小于设置的阈值
if (area < min_area)
{
// 遍历轮廓所在位置所有像素点
for (int i = rect.y; i < rect.y + rect.height; i++)
{
uchar *output_data = dst.ptr<uchar>(i);
for (int j = rect.x; j < rect.x + rect.width; j++)
{
// 将连通区的值置0
if (output_data[j] == 255)
{
output_data[j] = 0;
}
}
}
}
itc++;
}
}
}
详细可看:https://www.jb51.net/article/221904.htmhttps://www.jb51.net/article/221904.htm
边栏推荐
猜你喜欢
BatchNorm&&LayerNorm
PP-LiteSeg
简单说Q-Q图;stats.probplot(QQ图)
动手学深度学习__数据操作
(十一)树--堆排序
yolov3中数据读入(一)
【CV-Learning】目标检测&实例分割
RecyclerView的用法
【CV-Learning】卷积神经网络预备知识
[Deep Learning 21 Days Learning Challenge] 2. Complex sample classification and recognition - convolutional neural network (CNN) clothing image classification
随机推荐
[Deep Learning 21 Days Learning Challenge] 1. My handwriting was successfully recognized by the model - CNN implements mnist handwritten digit recognition model study notes
动手学深度学习__数据操作
TypeError: load() missing 1 required positional argument: ‘Loader‘
剑指 Offer 2022/7/1
图像形变(插值方法)
(十四)平衡二叉树
[Introduction to go language] 12. Pointer
yolov3中数据读入(一)
基于PyTorch的FCN-8s语义分割模型搭建
flink sql left join数据倾斜问题解决
记一次flink程序优化
(十五)B-Tree树(B-树)与B+树
yolov3数据读入(二)
TensorFlow2学习笔记:4、第一个神经网模型,鸢尾花分类
Th in thymeleaf: href use notes
WARNING: sql version 9.2, server version 11.0.Some psql features might not work.
双重指针的使用
Redis持久化方式RDB和AOF详解
Jupyter Notebook安装库;ModuleNotFoundError: No module named ‘plotly‘解决方案。
TensorFlow2 study notes: 8. tf.keras implements linear regression, Income dataset: years of education and income dataset