/* 程序名:hello.c
功能:从磁盘中读入图像文件,并将图像显示在屏幕上
*/
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
int main( int argc, char** argv )
{
IplImage* pImg,*pImg2; //声明IplImage指针
int row,col,row1,col1;
int sign;
int i=0;
if( argc == 3 && (pImg = cvLoadImage( argv[1], 1)) != 0 && (pImg2 = cvLoadImage( argv[2], 1)) != 0)
{
cvNamedWindow( "Image", CV_WINDOW_AUTOSIZE ); //创建窗口
cvShowImage( "Image", pImg ); //显示图像
cvNamedWindow( "Image2", CV_WINDOW_AUTOSIZE ); //创建窗口
cvShowImage( "Image2", pImg2 ); //显示图像
for(i=0;i<9;i++)
{
for(row1=row=(i/3)*(pImg->height/3);row<row1+(pImg->height/3);row++)
{
uchar* ptr=(uchar*)(pImg->imageData+row*pImg->widthStep);
uchar* ptr2=(uchar*)(pImg2->imageData+row*pImg2->widthStep);
sign=0;
for(col1=col=(i%3)*(pImg->width/3);col<col1+(pImg->width/3);col++)
{
if(ptr[3*col]!=ptr2[3*col]||ptr[3*col+1]!=ptr2[3*col+1]||ptr[3*col+2]!=ptr2[3*col+2])
{
sign=i;
continue;
}
}
if(sign!=0)
{
continue;
}
}
if(sign!=0)
{
printf("the %d picture is the same!",sign);
}
}
// if(row==pImg->height&&row==pImg2->height)printf("two pictures are the same!");
// else printf("two pictures are different!");
cvWaitKey(0); //等待按键
cvDestroyWindow( "Image" );//销毁窗口
cvReleaseImage( &pImg ); //释放图像
cvDestroyWindow( "Image2" );//销毁窗口
cvReleaseImage( &pImg2 ); //释放图像
return 0;
}
return -1;
}
分成3*3块比较