图像清晰度评价(模组自动对焦)Sobel算子--OpenCV

VS 2019
opencv-4.2.0-vc14_vc15

图像卷积及其滤波
Definition:convolution、noise reduction/smoothing/coherence/incoherence。
用coherence的灰度值取代incoherence的灰度值

Tenengrad梯度方法
Tenengrad梯度方法利用Sobel算子分别计算水平和垂直方向的梯度,同一场景下梯度值越高,图像越清晰。
经过Sobel算子处理后的图像的平均灰度值,值越大,代表图像越清晰。

Sobel( InputArray src, OutputArray dst, int ddepth,int dx, int dy, int ksize=3, double scale=1, double delta=0, int borderType=BORDER_DEFAULT );

函数参数介绍:
1、int ddepth : 图像深度,或者说图像处理后值的大小范围
2、dx,dy :决定是对横向和纵向的Sobel处理
3、 ksize :内核矩阵的大小,默认为3
4、 scale :函数处理后值乘以的系数,即 值scale
5、 delta :函数处理后值的补偿, 即值
scale + delta
函数使用:
cv::Sobel(image,sobelX,CV_8U,1,0,3,0.4,128);
cv::Sobel(image,sobelY,CV_8U,0,1,3,0.4,128);
cv::Sobel(image,outimage,CV_8U, 1,1);

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2\core\core.hpp>  
#include <opencv2\objdetect\objdetect.hpp>  
#include <opencv2\imgproc\types_c.h>  


using namespace std;
using namespace cv;
// Tenengrad梯度方法
int main()
{
	Mat imageSource = imread("D:\Project\testoutpic\1.jpg");
	Mat imageGrey;

	if (imageSource.empty())
	{

		cout << "could not load image..." << endl;

		return -1;
	}
	cvtColor(imageSource, imageGrey, CV_RGB2GRAY);
	Mat imageSobel;
	Sobel(imageGrey, imageSobel, CV_8U, 1, 1);

	//图像的平均灰度
	double meanValue = 0.0;
	meanValue = mean(imageSobel)[0];

	//double to string
	stringstream meanValueStream;
	string meanValueString;
	meanValueStream << meanValue;
	meanValueStream >> meanValueString;
	meanValueString = "Articulation(Sobel Method): " + meanValueString;
	putText(imageSource, meanValueString, Point(20, 50), FONT_HERSHEY_COMPLEX_SMALL, 0.8, Scalar(0, 0, 255), 2);
	//在imageSource图片上,显示Articulation(Sobel Method):+ meanValueString,位置在(20,50),字体类型为FONT_HERSHEY_COMPLEX_SMALL,字体大小为0.8,颜色为红色,字体厚度为2,线型默认为8.
	imshow("Articulation", imageSource);

	waitKey(0);

	cout << "Hello,world." << endl;

	return 0;
}
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值