求帧差程序

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

转载于:https://www.cnblogs.com/GarfieldEr007/p/5374103.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值