其他分享
首页 > 其他分享> > 激光光线滤波,形态学处理与中心点提取

激光光线滤波,形态学处理与中心点提取

作者:互联网

#include<opencv2/opencv.hpp>
#include<iostream>
#include<math.h>

using namespace std;
using namespace cv;

int main() {


	Mat src = imread("H:/3d_rebuild/2021_9_18/line/image_28.png");
	if (src.empty()) {
		cout << "not load..." << endl;
		return -1;
	}

	Mat fir = src;

	int a = src.channels();
	if (a = 3) {
		cout << "3 channels rgb picture" << endl;
		cvtColor(src, src, COLOR_BGR2GRAY);
	}
	else {
		cout << "1 channel gray picture" << endl;
	}

	Mat sed = src;

	threshold(src, src, 80, 255, THRESH_BINARY);

	Mat sor = src;

	Mat kernel = getStructuringElement(MORPH_RECT, Size(6, 6), Point(-1, -1));
	morphologyEx(src, src, CV_MOP_OPEN, kernel);

	std::vector<cv::Point2f> Points;

	for (size_t i = 0; i < src.rows; i++)
	{
		int sum = 0; int num = 0; size_t j = 0;
		for (j = 0; j < src.cols; j++)
		{
			if (src.at<uchar>(i, j) == 255)
			{
				sum += j;
				num++;
			}
		}
		if (num == 0)
			continue;
		
		src.at<uchar>(i, 1.0 * sum / num) = 0;
		Points.push_back(Point2f(i, 1.0 * sum / num));
		
	}
	
}

原图:

 滤波加提取中心点:

 开运算核的大小:

标签:src,int,sum,滤波,形态学,++,num,中心点,include
来源: https://blog.csdn.net/weixin_51229250/article/details/120721929