当前位置:网站首页>光条提取中的连通域筛除
光条提取中的连通域筛除
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
边栏推荐
- Use of double pointers
- k3s-轻量级Kubernetes
- 动手学深度学习_线性回归
- 完美解决keyby造成的数据倾斜导致吞吐量降低的问题
- SQL练习 2022/7/4
- Thoroughly understand box plot analysis
- Install dlib step pit record, error: WARNING: pip is configured with locations that require TLS/SSL
- 超详细MySQL总结
- Logistic Regression --- Introduction, API Introduction, Case: Cancer Classification Prediction, Classification Evaluation, and ROC Curve and AUC Metrics
- (十)树的基础部分(二)
猜你喜欢

(十五)B-Tree树(B-树)与B+树

动手学深度学习_线性回归

TensorFlow2学习笔记:5、常用激活函数

TensorFlow2 study notes: 6. Overfitting and underfitting, and their mitigation solutions

Deep Adversarial Decomposition: A Unified Framework for Separating Superimposed Images

彻底搞懂箱形图分析

Logistic Regression --- Introduction, API Introduction, Case: Cancer Classification Prediction, Classification Evaluation, and ROC Curve and AUC Metrics

PP-LiteSeg
![[CV-Learning] Convolutional Neural Network Preliminary Knowledge](/img/7d/58d9649b06e78eeb019d63615a90c4.png)
[CV-Learning] Convolutional Neural Network Preliminary Knowledge

flink on yarn指定第三方jar包
随机推荐
[CV-Learning] Convolutional Neural Network Preliminary Knowledge
动手学深度学习_多层感知机
【CV-Learning】目标检测&实例分割
读研碎碎念
JPEG2jpg
【CV-Learning】Image Classification
动手学深度学习__张量
yolov3 data reading (2)
Introduction of linear regression 01 - API use cases
SQL练习 2022/7/3
Dictionary feature extraction, text feature extraction.
剑指 Offer 2022/7/9
Learning curve learning_curve function in sklearn
软著撰写注意事项
k3s-轻量级Kubernetes
TensorFlow2学习笔记:8、tf.keras实现线性回归,Income数据集:受教育年限与收入数据集
postgres recursive query
剑指 Offer 20226/30
(TensorFlow)——tf.variable_scope和tf.name_scope详解
flink on yarn指定第三方jar包