当前位置:网站首页>激光条纹中心提取——灰度重心法
激光条纹中心提取——灰度重心法
2022-08-09 10:55:00 【[email protected]】
菜鸡的灰度重心法
灰度重心法的概念就不用我多哔哔了,做激光中心提取的同学都知道,灰度重心法应该说是最早的一种光条中心提取算法了,顾名思义就是根据灰度值的分布求出中心,所以往往要求灰度分布成高斯分布,但是实际情况是相反的,所以这种方法就只歇着,不过有很多灰度中心法结合或者改进比较常看到。
上代码
#include <opencv2/opencv.hpp>
#include <iostream>
#include <opencv2\imgproc\types_c.h>
#include<vector>
using namespace cv;
using std::vector;
using namespace std;
// 灰度重心法
void GGM(Mat src, int i) {
Mat srcimg;
srcimg = src;
Mat grayimg;
cvtColor(srcimg, grayimg, CV_BGR2GRAY);
GaussianBlur(grayimg, grayimg, Size(0, 0), 6, 6);
//traverse each column
float x0 = 0;
for (int i = 0; i < grayimg.cols; i++) {
float sum_value = 0;
float sum_valuecoor = 0;
vector<float>current_value;
vector<float>current_coordinat;
for (int j = 0; j < grayimg.rows; j++) {
float current = grayimg.at<uchar>(j, i);
//Save the point gray value and coordinates of the threshold into the array
if (current > 30) {
current_value.push_back(current);
current_coordinat.push_back(j);
}
}
//Calculate the gray center of gravity
for (int k = 0; k < current_value.size(); k++) {
sum_valuecoor += current_value[k] * current_coordinat[k];
sum_value += current_value[k];
}
float x = sum_valuecoor / sum_value;
x0 = x;
circle(srcimg, Point(i, x), 1, Scalar(0, 0, 255), -1, 8);
current_value.clear();
current_coordinat.clear();
}
namedWindow("gscog", 0);
resizeWindow("gscog", 800, 600);
imshow("gscog", srcimg);
string save_path = ".\\RailTurnout\\center\\" + to_string(i) + ".png";
cout << save_path << endl;
imwrite(save_path, srcimg);
waitKey(10);
}
int main() {
// 相对对路径
string path = ".\\RailTurnout\\result\\*.png";
cout << path << endl;
vector<Mat> images;
vector<String> fn;
glob(path, fn, false);
cout << fn.size() << endl;
size_t count = fn.size();
cout << count << endl;
for (int i = 0; i < count; i++) {
images.push_back(imread(fn[i]));
GGM(images[i], i);
/*imshow("pic", images[i]); waitKey(10);*/
}
system("pause");
return 0;
}
贴结果

左边是没有经过深度学习去噪处理的,右边是采用深度学习去噪处理的
我建立了一个激光条纹提取的群,欢迎小伙伴加入,学习交流:点击链接加入群聊【激光条纹中心提取】先申明本人是学生,不涉及营销、宣传、推广、盈利,单纯为了学习交流,所以心怀不轨的请绕道!!!
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://blog.csdn.net/CharmsLUO/article/details/122323140
边栏推荐
- 华为VRRP+MSTP联动接口检测实验案例
- 1003 Emergency (25分)
- Since I use the HiFlow scene connector, I don't have to worry about becoming a "dropper" anymore
- activemq 消息持久化
- 15.10 the POSIX semaphore Unix environment programming chapter 15
- WebSocket
- [华为云在线课程][SQL语法分类][数据操作][学习笔记]
- threejs+shader 曲线点运动,飞线运动
- 绝了,这套RESTful API接口设计总结
- Quartz分布式实现
猜你喜欢

Shell script combat (2nd edition) / People's Posts and Telecommunications Press Script 1 Find programs in the PATH

linux mysql操作的相关命令

Jmeter BeanShell post processor

985毕业,工作3年,分享从阿里辞职到了国企的一路辛酸和经验

activemq 消息持久化

Quartz的理解

【 original 】 VMware Workstation implementation Openwrt soft routing, the ESXI, content is very detailed!

商业技术解决方案与高阶技术专题 - 数据可视化专题

MATLAB代码实现三次样条插值

OpenSSF的开源软件风险评估工具:Scorecards
随机推荐
Unix Environment Programming Chapter 14 14.4 I/O Multiplexing
微信小程序——天气查询
聚类了解
Invisible OOM in kubernetes
shap库源码和代码实现
faster-rcnn learn
使用pip成功安装某个库,但pycharm中找不到,此问题的解决方案
Oracle数据库常用函数总结
Quartz分布式实现
MATLAB中如何把cftool拟合的函数输出到命令行(解决如何导出拟合后的曲线数据)
TensorFlow: NameError: name 'input_data' is not defined
1008 Elevator (20分)
爬虫实例,获取豆瓣上某部电影的评论
PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization Paper Reading
MySQL查询性能优化七种武器之索引潜水
faster-rcnn中的RPN原理
ThreadLocal及其内存泄露分析
String类型的字符串对象转实体类和String类型的Array转List
1007 Maximum Subsequence Sum (25分)
乘积量化(PQ)