www.pudn.com > DetectSharpAVI.rar > DetectSharp.cpp
#include "stdafx.h" #include#include #include struct SharpPrarm { unsigned int rbgcount; //当前rbg平均距离 unsigned int sharpcount; //当前清晰值 int rgbencroach; //当前rbg平均距离与阈值差值 int sharpencroach; //当前清晰值与阈值差值 bool warnning; //是否发出警告 bool sharp; //清晰true 不清晰false }; SharpPrarm DetectSharp(IplImage *Img, int RGBThreshold ,int GrayThreshold); int DetectBlurRGB(IplImage *Img); //用颜色之间的距离 int DetectGray(IplImage *GaryImg); //用平方梯度函数 int DetectBlur(IplImage *GrayImg,int x,int y,int width, int hight); /*********************************************************************** 检测函数: 参数:彩色图像, 颜色距离阈值,清晰度阈值 返回值:返回值为SharpPrarm结构体,计算出的阈值都大于给定阈值清晰图像,否则阈值模糊图像 阈值视频帧尺寸和场景有关系。 ***********************************************************************/ SharpPrarm DetectSharp(IplImage *Img, int RGBThreshold =15,int GrayThreshold =180) { SharpPrarm MyParam; IplImage *GrayImg = cvCreateImage(cvGetSize(Img), 8, 1); cvCvtColor(Img, GrayImg, CV_BGR2GRAY); int nrgb = DetectBlurRGB(Img); int ngray = DetectGray(GrayImg); if (nrgb width/3, GrayImg->height/3) )+ (unsigned int)(0.19*DetectBlur(GrayImg, GrayImg->width*2/3, 0, GrayImg->width, GrayImg->height/3))+ (unsigned int)(0.24*DetectBlur(GrayImg, GrayImg->width/3, GrayImg->height/3, GrayImg->width*2/3, GrayImg->height*2/3))+ (unsigned int)(0.19*DetectBlur(GrayImg, 0, GrayImg->height*2/3, GrayImg->width/3, GrayImg->height))+ (unsigned int)(0.19*DetectBlur(GrayImg, GrayImg->width*2/3, GrayImg->height*2/3, GrayImg->width, GrayImg->height)); return nCountSharp; } int DetectBlur(IplImage *GrayImg,int x,int y,int width, int hight) { double sharp =0, temp; CvScalar s1,s2; for(int i=y; i height-1; int width = Img->width; for(int i=0; i