#include "cv.h"
#include "highgui.h"
int main()
{
IplImage* img0=cvLoadImage("E:\\导出图片\\10000f.bmp");
IplImage* img1=cvLoadImage("E:\\导出图片\\11020f.bmp");
CvMat* Mat0 = NULL;
CvMat* Mat1 = NULL;
CvRect rect0,rect1;
rect0.x=0;
rect0.y=400;
rect0.height=300;
rect0.width=200;
rect1.x=0;
rect1.y=400;
rect1.height=300;
rect1.width=200;
cvSetImageROI( img0, rect0 );
cvSetImageROI( img0, rect1 );
cvNamedWindow( "tem image" );
cvShowImage("tem image",img0);///显示pImg大小为48*48
cvNamedWindow( "tem image1" );
cvShowImage("tem image1",img1);///显示pImg大小为48*48
IplImage *selimg0=cvCreateImage(cvSize(rect0.width,rect0.height),IPL_DEPTH_8U,1);
selimg0=(IplImage*)cvClone(img0);
IplImage *selimg1=cvCreateImage(cvSize(rect1.width,rect1.height),IPL_DEPTH_8U,1);
selimg1=(IplImage*)cvClone(img1);
Mat0 = cvCreateMat(selimg0->height, selimg0->width, CV_32FC1);
Mat1 = cvCreateMat(selimg1->height, selimg1->width, CV_32FC1);
cvCvtColor(img0, selimg0, CV_BGR2GRAY);
cvConvert(selimg0, Mat0);//图像转为矩阵
cvCvtColor(img1, selimg1, CV_BGR2GRAY);
cvConvert(selimg1, Mat1);//图像转为矩阵
double t = cvNorm(Mat0,Mat1,CV_RELATIVE_L2,NULL);
//cvNamedWindow( "select pImage");//可以看到selimg->width,selimg->height还是原图大小
//cvShowImage("select pImage",selimg);///显示pImg大小为48*48
// cvSaveImage("hello2.jpg",selimg);
cvResetImageROI(img0);
cvResetImageROI(img1);
printf("%d\n",t);
system("PAUSE");
cvWaitKey(0);
return 0;
}