当前位置:网站首页>光条提取中的连通域筛除
光条提取中的连通域筛除
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
边栏推荐
- Logistic Regression --- Introduction, API Introduction, Case: Cancer Classification Prediction, Classification Evaluation, and ROC Curve and AUC Metrics
- TensorFlow2学习笔记:5、常用激活函数
- 0, deep learning 21 days learning challenge 】 【 set up learning environment
- [Go language entry notes] 13. Structure (struct)
- flink问题整理
- (九)哈希表
- Kubernetes基本入门-名称空间资源(三)
- postgres 递归查询
- JPEG2jpg
- Kubernetes基础入门(完整版)
猜你喜欢
Data reading in yolov3 (1)
Vision Transformer 论文 + 详解( ViT )
Introduction of linear regression 01 - API use cases
Jupyter Notebook安装库;ModuleNotFoundError: No module named ‘plotly‘解决方案。
双重指针的使用
TensorFlow2学习笔记:5、常用激活函数
with recursive用法
MAE 论文《Masked Autoencoders Are Scalable Vision Learners》
Polynomial Regression (PolynomialFeatures)
【深度学习21天学习挑战赛】1、我的手写被模型成功识别——CNN实现mnist手写数字识别模型学习笔记
随机推荐
(五)栈及其应用
剑指 Offer 2022/7/11
(TensorFlow)——tf.variable_scope和tf.name_scope详解
【go语言入门笔记】13、 结构体(struct)
Kubernetes基本入门-概念介绍(一)
Vision Transformer 论文 + 详解( ViT )
sklearn中的pipeline机制
Various commands such as creating a new user in postgresql
字典特征提取,文本特征提取。
SQL练习 2022/7/5
动手学深度学习_卷积神经网络CNN
剑指 Offer 2022/7/3
CAS与自旋锁、ABA问题
动手学深度学习_softmax回归
Thoroughly understand box plot analysis
动手学深度学习__张量
多项式回归(PolynomialFeatures)
Install dlib step pit record, error: WARNING: pip is configured with locations that require TLS/SSL
简单明了,数据库设计三大范式
yolov3中数据读入(一)