当前位置:网站首页>光条提取中的连通域筛除
光条提取中的连通域筛除
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.htm
https://www.jb51.net/article/221904.htm
边栏推荐
猜你喜欢
随机推荐
Learning curve learning_curve function in sklearn
android基础 [超级详细android存储方式解析(SharedPreferences,SQLite数据库存储)]
动手学深度学习_线性回归
(TensorFlow)——tf.variable_scope和tf.name_scope详解
MySql--存储引擎以及索引
oracle的number与postgresql的numeric对比
Image-Adaptive YOLO for Object Detection in Adverse Weather Conditions
【深度学习21天学习挑战赛】1、我的手写被模型成功识别——CNN实现mnist手写数字识别模型学习笔记
WARNING: sql version 9.2, server version 11.0. Some psql features might not work.
Kubernetes基本入门-概念介绍(一)
flink-sql所有语法详解
Install dlib step pit record, error: WARNING: pip is configured with locations that require TLS/SSL
Various commands such as creating a new user in postgresql
sklearn中的pipeline机制
动手学深度学习__数据操作
剑指 Offer 2022/7/8
【CV-Learning】目标检测&实例分割
WARNING: sql version 9.2, server version 11.0.Some psql features might not work.
[Deep Learning 21 Days Learning Challenge] Memo: What does our neural network model look like? - detailed explanation of model.summary()
flink on yarn指定第三方jar包







