BMP圖像分割C語(yǔ)言程序.docx_第1頁(yè)
BMP圖像分割C語(yǔ)言程序.docx_第2頁(yè)
BMP圖像分割C語(yǔ)言程序.docx_第3頁(yè)
BMP圖像分割C語(yǔ)言程序.docx_第4頁(yè)
BMP圖像分割C語(yǔ)言程序.docx_第5頁(yè)
已閱讀5頁(yè),還剩7頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

BMP圖像差分C語(yǔ)言程序:#include #include typedef unsigned short WORD;typedef unsigned long DWORD;typedef long LONG;typedef unsigned char BYTE;typedef struct BITMAPFILEHEADER WORD bfType; DWORD bfSize; WORD bfReserved1; WORD bfReserved2; DWORD bfOffbits; BITMAPFILEHEADER,*PBITMAPFILEHEADER;typedef struct BITMAPINFOHEADER DWORD biSize; LONG biWidth; LONG biHeight; WORD biPlanes; WORD biBitCount; DWORD biCompression; DWORD biSizeImage; LONG biXPlesPerMeter; LONG biYPlesPerMeter; DWORD biClrUsed; DWORD biClrImportant; BITMAPINFOHEADER,*PBITMAPINFOHEADER;typedef struct RGBQUAD BYTE rgbBlue; BYTE rgbGreen; BYTE rgbRed; BYTE rgbReserved; RGBQUAD;int main(int argc,char *argv) BITMAPFILEHEADER mapfileheader; BITMAPINFOHEADER mapinfoheader; DWORD bfSize1=0; DWORD bfSize2; DWORD bfOffbits1; DWORD bfOffbits2; DWORD biWidth1; DWORD biWidth2; DWORD biHeight1; DWORD biHeight2; WORD biBitCount1; WORD biBitCount2; LONG biXPlesPerMeter1; LONG biXPlesPerMeter2; LONG biYPlesPerMeter1; LONG biYPlesPerMeter2; BYTE a; BYTE b; BYTE c; FILE *fp1=0; FILE *fp2=0; FILE *fpa=0; FILE *fpb=0; DWORD line_bytes1; DWORD line_bytes2; BYTE *pixel1; BYTE *pixel2; BYTE *pixel3; int i=0; int j=0; RGBQUAD pal256; int ret1; int ret2; if(argc!=3) printf(Please input the path of the file.n); return 1; fp1=fopen(argv1,rb); if(!fp1) printf(Cannot open the first file.n); return 1; fp2=fopen(argv2,rb); if(!fp2) printf(Cannot open the second file.n);return 1; fseek(fp1,10,SEEK_SET); fseek(fp2,10,SEEK_SET); if(fread(&bfOffbits1,4,1,fp1)!=1) printf(Cannot read bfOffbits of the head of the first file.n); fclose(fp1); fclose(fp2); return 1; printf(bfOffbits1:%dn,bfOffbits1); if(fread(&bfOffbits2,4,1,fp2)!=1) printf(Cannot read bfOffbits of the head of the second file.n); fclose(fp1); fclose(fp2); return 1; printf(bfOffbits2:%dn,bfOffbits2); fseek(fp1,18,SEEK_SET); fseek(fp2,18,SEEK_SET); if(fread(&biWidth1,4,1,fp1)!=1) printf(Cannot read biWidth of the head of the first file.n); fclose(fp1); fclose(fp2); return 1; printf(biWidth1:%dn,biWidth1); if(fread(&biWidth2,4,1,fp2)!=1) printf(Cannot read biWidth of the head of second file.n); fclose(fp1); fclose(fp2); return 1; printf(biWidth2:%dn,biWidth2); if(fread(&biHeight1,4,1,fp1)!=1) printf(Cannot read biHeight1 of the head.n); fclose(fp1); fclose(fp2); return 1; printf(biHeight1:%dn,biHeight1); if(fread(&biHeight2,4,1,fp2)!=1) printf(Cannot read biHeight2 of the head.n); fclose(fp1); fclose(fp2); return 1; printf(biHeight2:%dn,biHeight2); fseek(fp1,28,SEEK_SET); fseek(fp2,28,SEEK_SET); if(fread(&biBitCount1,2,1,fp1)!=1) printf(Cannot read biBitCount1 of the head.n); fclose(fp1); fclose(fp2); return 1; printf(biBitCount1:%dn,biBitCount1); if(fread(&biBitCount2,2,1,fp2)!=1) printf(Cannot read biBitCount2 of the head.n); fclose(fp1); fclose(fp2); return 1; printf(biBItCount2:%dn,biBitCount2); if(biBitCount1!=biBitCount2) printf(Two picutres have different biBitCount.n); fclose(fp1); fclose(fp2); return 1; fseek(fp1,sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER),SEEK_SET); fseek(fp2,sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER),SEEK_SET); for(i=0;i255;i+) fread(&pali.rgbBlue,1,1,fp1); fread(&pali.rgbGreen,1,1,fp1); fread(&pali.rgbRed,1,1,fp1); pali.rgbReserved=0; line_bytes1=(biWidth1*biBitCount1+31)/32*4; line_bytes2=(biWidth2*biBitCount2+31)/32*4; pixel1=(BYTE*)malloc(biHeight1*line_bytes1*sizeof(BYTE); memset(pixel1,0,biHeight1*line_bytes1*sizeof(BYTE); if(pixel1=0) printf(Fail to allocate memory to File one.n); fclose(fp1); fclose(fp2); return 1; pixel2=(BYTE*)malloc(biHeight2*line_bytes2*sizeof(BYTE); memset(pixel2,0,biHeight2*line_bytes2*sizeof(BYTE); if(pixel2=0) printf(Fail to allocate memory to File two.n); fclose(fp1); fclose(fp2); return 1; pixel3=(BYTE*)malloc(biHeight2*line_bytes2*sizeof(BYTE); memset(pixel3,0,biHeight1*line_bytes1*sizeof(BYTE); printf(an); fseek(fp1,bfOffbits1,SEEK_SET); fseek(fp2,bfOffbits2,SEEK_SET); if(fread(pixel2,biHeight1*line_bytes1*sizeof(BYTE),1,fp2)=0) printf(Cannot read pixels of the file two.n); free(pixel2); pixel2=NULL; fclose(fp1); fclose(fp2); return 1; if(fread(pixel1,biHeight2*line_bytes2*sizeof(BYTE),1,fp1)=0) printf(Cannot read pixels of the file one.n); free(pixel1); pixel1=NULL; fclose(fp1); fclose(fp2); return 1; printf(an); if(biBitCount1=8) printf(an); for(i=0;ibiHeight1;i+) for(j=0;jbiWidth1;j+) a=line_bytes1*i+j; if(pixel1a-pixel2a=0) pixel3a=0; else pixel3a=pixel2a; printf(an); else printf(Only support 8 or 24 bits Bitmap.n); free(pixel1); pixel1=NULL; free(pixel2); pixel2=NULL; fclose(fp1); fclose(fp2); return 1; fclose(fp1); fclose(fp2); free(pixel1); free(pixel2); pixel1=NULL; pixel2=NULL; mapfileheader.bfType=19778; mapfileheader.bfSize=bfSize1; mapfileheader.bfReserved1=0; mapfileheader.bfReserved2=0; mapfileheader.bfOffbits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256; mapinfoheader.biSize=sizeof(BITMAPINFOHEADER); mapinfoheader.biWidth=biWidth1; mapinfoheader.biHeight=biHeight1; mapinfoheader.biPlanes=1; mapinfoheader.biBitCount=biBitCount1; mapinfoheader.biCompression=0; mapinfoheader.biSizeImage=biHeight1*line_bytes1; mapinfoheader.biXPlesPerMeter=0; mapinfoheader.biYPlesPerMeter=0; mapinfoheader.biClrUsed=0; mapinfoheader.biClrImportant=0; fpa=fopen(E:/Win_TC/File/test.bmp,wb); fclose(fpa); /*fpb=fopen(E:Win-TCFiletest.bmp,wb); if(!fpb) printf(Cannot creat a new file.n); return 1; fwrite(&mapfileheader,sizeof(BITMAPFILEHEADER),1,fpb); fwrite(&mapinfoheader,sizeof(BITMAPINFOHEADER),1,fpb); fwrite(pal,sizeof(RGBQUAD),256,fpb); fwrite(pixel3,sizeof(BYTE)*line_bytes1*biHeight1,1,fpb); fclose(fpb);*/ printf(Success.); getch(); return 0;#include #include #include #include int main( int argc, char* argv ) /聲明IplImage指針 IplImage* pFrame = NULL; IplImage* pFrImg = NULL; IplImage* pBkImg = NULL; CvMat* pFrameMat = NULL; CvMat* pFrMat = NULL; CvMat* pBkMat = NULL; CvCapture* pCapture = NULL; int nFrmNum = 0; /創(chuàng)建窗口 cvNamedWindow(video, 1); cvNamedWindow(background,1); cvNamedWindow(foreground,1); /使窗口有序排列 cvMoveWindow(video, 30, 0); cvMoveWindow(background, 360, 0); cvMoveWindow(foreground, 690, 0); if( argc 2 ) fprintf(stderr, Usage: bkgrd video_file_namen); return -1; /打開(kāi)攝像頭 if (argc =1) if( !(pCapture = cvCaptureFromCAM(-1) fprintf(stderr, Can not open camera.n);return -2; /打開(kāi)視頻文件 if(argc = 2) if( !(pCapture = cvCaptureFromFile(argv1) fprintf(stderr, Can not open video file %sn, argv1);return -2; /逐幀讀取視頻 while(pFrame = cvQueryFrame( pCapture ) nFrmNum+; /如果是第一幀,需要申請(qǐng)內(nèi)存,并初始化 if(nFrmNum = 1) pBkImg = cvCreateImage(cvSize(pFrame-width, pFrame-height), IPL_DEPTH_8U,1); pFrImg = cvCreateImage(cvSize(pFrame-width, pFrame-height), IPL_DEPTH_8U,1); pBkMat = cvCreateMat(pFrame-height, pFrame-width, CV_32FC1); pFrMat = cvCreateMat(pFrame-height, pFrame-width, CV_32FC1); pFrameMat = cvCreateMat(pFrame-height, pFrame-width, CV_32FC1); /轉(zhuǎn)化成單通道圖像再處理 cvCvtColor(pFrame, pBkImg

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論