求帧差程序
2016-04-10 14:20 GarfieldEr007 阅读(199) 评论(0) 编辑 收藏 举报yuv player弄个出来的帧差效果很差,看不清, 改成bmp再弄会好很多:
多亏钱建大师帮忙,留底以后大家省的写了!
代码如下:
//********************************************************************** //@2011/7/21 10:05:21 //@Author: 钱建 & 张睿卿 //********************************************************************** #include"iostream" #include "highgui.h" #include <conio.h> #include <stdlib.h> #include "math.h" #include "cv.h" #include "highgui.h" #include "cxcore.h" using namespace std; int Width; int Height; int T; IplImage* IplImageFrameSub; unsigned char *templast,*tempcur,*temp2y; CvScalar s,s1; void FD() { int i,j; IplImage *file_input_src1=cvLoadImage("C:\\Users\\Zrq\\Desktop\\c1.bmp",1); IplImage *file_input_src2=cvLoadImage("C:\\Users\\Zrq\\Desktop\\c2.bmp",1); Width=min(file_input_src1->width,file_input_src2->width); Height=min(file_input_src1->height,file_input_src2->height); templast=(unsigned char*)malloc(Height *Width*3/2*sizeof(unsigned char*)); tempcur=(unsigned char*)malloc(Height *Width*3/2*sizeof(unsigned char*)); temp2y=(unsigned char*)malloc(Height *Width*3/2*sizeof(unsigned char*)); IplImageFrameSub=cvCloneImage(file_input_src1); for (i=0; i<Height; i++) for (j=0; j<Width; j++) { s=cvGet2D(file_input_src1,i,j); templast[i*Width+j]=unsigned char(s.val[0]); s=cvGet2D(file_input_src2,i,j); tempcur[i*Width+j]=unsigned char(s.val[0]); } cout<<"Load Succeed!"<<endl; for (j=0; j<Height; j++) for (i=0; i<Width; i++) { temp2y[j*Width+i]=((abs(templast[j*Width+i]-tempcur[j*Width+i]))<=T ? 0: 255); } for (j = 0;j < Height;j++) for(i = 0;i < Width;i++) templast[j*Width+i] = tempcur[j * Width + i]; cout<<"Begin Save BMP"<<endl; for (j=0; j<Height; j++) for (i=0; i<Width; i++) { s1.val[0]=temp2y[j*Width+i]; cvSet2D(IplImageFrameSub,j,i,s1); } cout<<"OK!"<<endl; cvSaveImage("D:\\数字图象处理\\MVD-break61(帧差1).bmp",IplImageFrameSub); } void main() { cout<<"input T"<<endl; cin>>T; FD(); }
from: http://blog.csdn.net/abcjennifer/article/details/6621986