#include"cv.h"
#include"highgui.h"
#include<iostream>
using namespace std;
double focus(IplImage* image);
int main() {
IplImage* previous1;
IplImage* previous2;
IplImage* previous3;
IplImage* previous4;
previous1=cvLoadImage("e://temporary/test01.bmp",);
previous2=cvLoadImage("e://temporary/test02.bmp",);
previous3=cvLoadImage("e://temporary/test03.bmp",);
previous4=cvLoadImage("e://temporary/test04.bmp",);
if(previous1!=&&previous2!=&&previous3!=&&previous4!=)
{
cvNamedWindow("previous1",);
cvShowImage("previous1",previous1); cvNamedWindow("previous2",);
cvShowImage("previous2",previous2); cvNamedWindow("previous3",);
cvShowImage("previous3",previous3); cvNamedWindow("previous4",);
cvShowImage("previous4",previous4);
cout<<"The definition of the previous1 is: "<<focus(previous1)<<endl;
cout<<"The definition of the previous2 is: "<<focus(previous2)<<endl;
cout<<"The definition of the previous3 is: "<<focus(previous3)<<endl;
cout<<"The definition of the previous4 is: "<<focus(previous4)<<endl;
//关掉窗口,结束 cvWaitKey(0);
cvDestroyWindow("previous1");
cvReleaseImage(&previous1);
cvDestroyWindow("previous2");
cvReleaseImage(&previous2);
cvDestroyWindow("previous3");
cvReleaseImage(&previous3);
cvDestroyWindow("previous4");
cvReleaseImage(&previous4); return ; }
return -;
}
double focus(IplImage* image) {
IplImage* picone=cvCreateImage(cvGetSize(image),,);
cvCvtColor(image,picone,CV_BGR2YCrCb);
CvScalar gety;
double z=,zy1=,zy2=,total=; double gety1=,gety2=; double final=;
for(int ix=;ix<(picone->height);ix++)
{
gety1=;
gety2=;
zy1=;
zy2=;
for(int jy=;jy<(picone->width);jy++)
{
gety=cvGet2D(picone,ix,jy);
z=0.5*gety.val[]-gety1+0.5*gety2+zy1-0.5*zy2;
total=total+z;
gety2=gety1;
gety1=gety.val[]; zy2=zy1; zy1=z;
}
}
cvReleaseImage(&picone);
final=abs(total/((image->height)*(image->width)));
return final;
}