• 求帧差程序


    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

  • 相关阅读:
    get_json_object 用法
    vim中的特殊字符
    vim常用命令
    mac下如何配置用户的环境变量
    vim如何替换^M ?
    git ssh 配置
    mac上pip install时提示/System/Library/... 无权限
    mysql语句--table中某列有多值时,删除其他,仅保留1条
    mysql语句如何把多行的数据合并到一行?
    微服务分布式电商项目学习笔记(二)---- 微服务架构图+微服务划分图(2020/7/1)
  • 原文地址:https://www.cnblogs.com/GarfieldEr007/p/5374103.html
Copyright © 2020-2023  润新知