BMP图像分割C语言程序_第1页
BMP图像分割C语言程序_第2页
BMP图像分割C语言程序_第3页
BMP图像分割C语言程序_第4页
BMP图像分割C语言程序_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、BMP图像差分C语言程序:#include <stdio.h>#include <stdlib.h>typedef unsigned short WORD;typedef unsigned long DWORD;typedef long LONG;typedef unsigned char BYTE;typedef struct BITMAPFILEHEADER         WORD bfType;       

2、60; DWORD bfSize;         WORD bfReserved1;         WORD bfReserved2;         DWORD bfOffbits;         BITMAPFILEHEADER,*PBITMAPFILEHEADER;t

3、ypedef struct BITMAPINFOHEADER         DWORD biSize;         LONG biWidth;         LONG biHeight;         WORD biPlanes;   &#

4、160;     WORD biBitCount;         DWORD biCompression;         DWORD biSizeImage;         LONG biXPlesPerMeter;        

5、LONG biYPlesPerMeter;         DWORD biClrUsed;         DWORD biClrImportant;         BITMAPINFOHEADER,*PBITMAPINFOHEADER;typedef struct RGBQUAD      &

6、#160;  BYTE rgbBlue;         BYTE rgbGreen;         BYTE rgbRed;         BYTE rgbReserved;         RGBQUAD;int main(int argc,char *argv

7、)      BITMAPFILEHEADER mapfileheader;      BITMAPINFOHEADER mapinfoheader;      DWORD bfSize1=0;      DWORD bfSize2;      DWORD bfOffbits1;      DWOR

8、D bfOffbits2;      DWORD biWidth1;      DWORD biWidth2;      DWORD biHeight1;      DWORD biHeight2;      WORD biBitCount1;      WORD biBitCount2; 

9、;     LONG biXPlesPerMeter1;      LONG biXPlesPerMeter2;      LONG biYPlesPerMeter1;      LONG biYPlesPerMeter2;      BYTE a;      BYTE b;   

10、;   BYTE c;      FILE *fp1=0;      FILE *fp2=0;       FILE *fpa=0;      FILE *fpb=0;      DWORD line_bytes1;      DWORD line_bytes2; &#

11、160;    BYTE *pixel1;      BYTE *pixel2;      BYTE *pixel3;      int i=0;      int j=0;      RGBQUAD pal256;      int ret1;  

12、    int ret2;      if(argc!=3)            printf("Please input the path of the file.n");      return 1;            fp1=f

13、open(argv1,"rb");      if(!fp1)            printf("Cannot open the first file.n");      return 1;            fp2=fopen(argv2,

14、"rb");      if(!fp2)             printf("Cannot open the second file.n");      return 1;            fseek(fp1,10,SEEK_SE

15、T);      fseek(fp2,10,SEEK_SET);      if(fread(&bfOffbits1,4,1,fp1)!=1)               printf("Cannot read bfOffbits of the head of the first file.n");   

16、60;        fclose(fp1);            fclose(fp2);            return 1;            printf("bfOffbits1:%

17、dn",bfOffbits1);      if(fread(&bfOffbits2,4,1,fp2)!=1)                  printf("Cannot read bfOffbits of the head of the second file.n");      &#

18、160;     fclose(fp1);            fclose(fp2);            return 1;            printf("bfOffbits2:%dn",bfOffbit

19、s2);      fseek(fp1,18,SEEK_SET);      fseek(fp2,18,SEEK_SET);      if(fread(&biWidth1,4,1,fp1)!=1)                  printf("Cannot read

20、 biWidth of the head of the first file.n");            fclose(fp1);            fclose(fp2);            return 1;   

21、         printf("biWidth1:%dn",biWidth1);      if(fread(&biWidth2,4,1,fp2)!=1)                  printf("Cannot read biWidth of the head of se

22、cond file.n");            fclose(fp1);            fclose(fp2);            return 1;        

23、0;   printf("biWidth2:%dn",biWidth2);      if(fread(&biHeight1,4,1,fp1)!=1)                  printf("Cannot read biHeight1 of the head.n");   

24、0;        fclose(fp1);            fclose(fp2);            return 1;            printf("biHeight1:%dn

25、",biHeight1);      if(fread(&biHeight2,4,1,fp2)!=1)                  printf("Cannot read biHeight2 of the head.n");          &

26、#160; fclose(fp1);            fclose(fp2);            return 1;            printf("biHeight2:%dn",biHeight2);   

27、60;  fseek(fp1,28,SEEK_SET);      fseek(fp2,28,SEEK_SET);      if(fread(&biBitCount1,2,1,fp1)!=1)                  printf("Cannot read biBitCount1 of the he

28、ad.n");            fclose(fp1);            fclose(fp2);            return 1;          

29、;  printf("biBitCount1:%dn",biBitCount1);       if(fread(&biBitCount2,2,1,fp2)!=1)                  printf("Cannot read biBitCount2 of the head.n");   

30、         fclose(fp1);            fclose(fp2);            return 1;            printf("biBItCoun

31、t2:%dn",biBitCount2);      if(biBitCount1!=biBitCount2)                  printf("Two picutres have different biBitCount.n");         &#

32、160;  fclose(fp1);            fclose(fp2);            return 1;            fseek(fp1,sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER),

33、SEEK_SET);      fseek(fp2,sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER),SEEK_SET);      for(i=0;i<255;i+)                 fread(&pali.rgbBlue,1,1,fp1);  &

34、#160;        fread(&pali.rgbGreen,1,1,fp1);           fread(&pali.rgbRed,1,1,fp1);           pali.rgbReserved=0;        &#

35、160;                  line_bytes1=(biWidth1*biBitCount1+31)/32*4;      line_bytes2=(biWidth2*biBitCount2+31)/32*4;      pixel1=(BYTE*)malloc(biHeight1*line_bytes1*si

36、zeof(BYTE);      memset(pixel1,0,biHeight1*line_bytes1*sizeof(BYTE);      if(pixel1=0)                 printf("Fail to allocate memory to File one.n");  &#

37、160;        fclose(fp1);           fclose(fp2);           return 1;            pixel2=(BYTE*)malloc(biHeight2*line_

38、bytes2*sizeof(BYTE);      memset(pixel2,0,biHeight2*line_bytes2*sizeof(BYTE);      if(pixel2=0)                 printf("Fail to allocate memory to File two.n"); 

39、;          fclose(fp1);           fclose(fp2);           return 1;            pixel3=(BYTE*)malloc(biHeig

40、ht2*line_bytes2*sizeof(BYTE);      memset(pixel3,0,biHeight1*line_bytes1*sizeof(BYTE);                     printf("an");      fseek(fp1,bfOf

41、fbits1,SEEK_SET);      fseek(fp2,bfOffbits2,SEEK_SET);      if(fread(pixel2,biHeight1*line_bytes1*sizeof(BYTE),1,fp2)=0)                      

42、60;        printf("Cannot read pixels of the file two.n");           free(pixel2);           pixel2=NULL;        &#

43、160;  fclose(fp1);           fclose(fp2);           return 1;            if(fread(pixel1,biHeight2*line_bytes2*sizeof(BYTE),1,fp1)=0)  

44、                   printf("Cannot read pixels of the file one.n");           free(pixel1);           pixe

45、l1=NULL;           fclose(fp1);           fclose(fp2);           return 1;            printf("a

46、n");          if(biBitCount1=8)                 printf("an");           for(i=0;i<biHeight1;i+)   

47、;                         for(j=0;j<biWidth1;j+)                       &

48、#160;                 a=line_bytes1*i+j;                        if(pixel1a-pixel2a=0)   &#

49、160;                                                 pixel3a=0;&#

50、160;                                               else   &#

51、160;                                               pixel3a=pixel2a;

52、60;                                                    

53、     printf("an");            else                printf("Only support 8 or 24 bits Bitmap.n");       

54、60;  free(pixel1);          pixel1=NULL;          free(pixel2);          pixel2=NULL;          fclose(fp1); &#

55、160;        fclose(fp2);          return 1;            fclose(fp1);      fclose(fp2);      free(pixel1);  

56、0;   free(pixel2);      pixel1=NULL;      pixel2=NULL;      mapfileheader.bfType=19778;      mapfileheader.bfSize=bfSize1;      mapfileheader.bfReserved1=0; 

57、60;    mapfileheader.bfReserved2=0;      mapfileheader.bfOffbits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256;      mapinfoheader.biSize=sizeof(BITMAPINFOHEADER);      mapinfoheader.biW

58、idth=biWidth1;      mapinfoheader.biHeight=biHeight1;      mapinfoheader.biPlanes=1;      mapinfoheader.biBitCount=biBitCount1;      mapinfoheader.biCompression=0;      mapinf

59、oheader.biSizeImage=biHeight1*line_bytes1;      mapinfoheader.biXPlesPerMeter=0;      mapinfoheader.biYPlesPerMeter=0;      mapinfoheader.biClrUsed=0;      mapinfoheader.biClrImportant=0;  &

60、#160;   fpa=fopen("E:/Win_TC/File/test.bmp","wb");      fclose(fpa);      /*fpb=fopen("E:Win-TCFiletest.bmp","wb");      if(!fpb)        

61、60;          printf("Cannot creat a new file.n");             return 1;            fwrite(&mapfileheader,sizeof(BITMAPFILEHEADER),1

62、,fpb);      fwrite(&mapinfoheader,sizeof(BITMAPINFOHEADER),1,fpb);      fwrite(pal,sizeof(RGBQUAD),256,fpb);      fwrite(pixel3,sizeof(BYTE)*line_bytes1*biHeight1,1,fpb);      fclose(fpb);*/ 

63、     printf("Success.");      getch();      return 0;      #include <stdio.h> #include <cv.h>#include <cxcore.h>#include <highgui.h> int main( int argc, char* argv ) /声明IplImage指针 IplImage* pFrame = NULL; IplImage* pFrImg = NULL; IplImage* pBkImg = NULL;  CvMat* pFrameMat = NULL; CvMat* pFrMat = NULL; CvMat* pBkMat = N

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论