学习openCV,需要动态监测视频中的光斑,并绘制轮廓
openCV中的二值化,可以过滤出较大块的高亮区域,测试代码中使用灰度阈值230-255之间来获取
并将其轮廓获取,求出轮廓的大小面积,并求拟合椭圆,从而得出光斑的位置和中心,具体实现代码和效果如下:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
Mat process(Mat& srcImg)
{
Mat dstImg = srcImg.clone();
Mat tempImg = srcImg.clone();
cvtColor(tempImg, tempImg, CV_BGR2GRAY);//色域转换
GaussianBlur(tempImg, tempImg, Size(3, 3), 0, 0);//高斯滤波
threshold(tempImg, tempImg, 230,