## 一、背景差分法和帧间差分法的车辆运动目标检测简介

1 引言

1 算法介绍
1.1 背景差分法

Ek(x,y)=|Pk(x,y)−Bk(x,y)|         (1)

1.2 帧间差分法

Ek(x,y)=|Pk(x,y)−Pk−1(x,y)|         (3)

2 算法改进
2.1 背景建模

2.2 背景差分二值化

2.3 图像边缘检测

2.4 边缘图像差分

EG(x,y).EG(x,y)=|EG2(x,y)−EG1(x,y)|         (12)

2.5 图像后处理

## 二、部分源代码

function varargout = Main_object_tracking(varargin)% _____________________________________________________% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, ...    'gui_Singleton',  gui_Singleton, ...    'gui_OpeningFcn', @Main_object_tracking_OpeningFcn, ...    'gui_OutputFcn',  @Main_object_tracking_OutputFcn, ...    'gui_LayoutFcn',  [] , ...    'gui_Callback',   []);if nargin && ischar(varargin{1})    gui_State.gui_Callback = str2func(varargin{1});endif nargout    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else    gui_mainfcn(gui_State, varargin{:});end% End initialization code - DO NOT EDIT% --- Executes just before Main_object_tracking is made visible.function Main_object_tracking_OpeningFcn(hObject, eventdata, handles, varargin)movegui(hObject,'center')imaqreset% ID of video sourcehandles.fuente=2;%Disable "Start" and "Stop" buttonsset(handles.inicio,'Enable','off');set(handles.parar,'Enable','off');set(hObject,'UserData',0)set(handles.axes1,'XTickLabel',[],'YTickLabel',[])% Choose default command line output for Main_object_trackinghandles.output = hObject;% Update handles structureguidata(hObject, handles);% --- Outputs from this function are returned to the command line.function varargout = Main_object_tracking_OutputFcn(hObject, eventdata, handles)% Get default command line output from handles structurevarargout{1} = handles.output;% --- FUNCTION TO GET BACKGROUNDfunction cap_fondo_Callback(hObject, eventdata, handles)% Reset imaq deviceimaqresetset(hObject,'UserData',0) %User data 0 (1 stop capture)% Enable "Start" and "Stop" buttonsset(handles.inicio,'Enable','off');set(handles.parar,'Enable','off');% Disable current buttonset(hObject,'Enable','off');% Get default sourcesel_fuente=handles.fuente;switch sel_fuente    % _________________________________________________________________    case 1 %WEB CAM                % Open GUI to select the camera to use        sel_camera        %        uiwait        % Bring the camera features        % id= Camera ID        % es_web_ext= indicator if laptop or external camera        global id es_web_ext        % Determine format depending on the type of camera to use        if es_web_ext==0            formato='YUY2_176x144';        else            formato='RGB24_320x240';        end        try            % Create video object            vid = videoinput('winvideo',id,formato);            % Update handles            guidata(hObject, handles);                    catch            % Message on error            msgbox('Check the connection of the camera','Camera')            % Remove axis labels            set(handles.axes1,'XTick',[ ],'YTick',[ ])        end        % Specify how often to acquire frame from video stream        vid.FrameGrabInterval = 1;        set(vid,'TriggerRepeat',Inf);        % Start capture        % _______Get Background_________        vid.FramesPerTrigger=50;        start(vid);        data = getdata(vid,50);        if es_web_ext==0            fondo=double(ycbcr2rgb(data(:,:,:,50)));        else            fondo=double(data(:,:,:,50));        end        % Set last image as background        % Show background        imshow(uint8(fondo))        % Reset video object        stop(vid);        clear vid        imaqreset    case 2%VIDEO AVI        [nombre, ruta]=uigetfile('*.avi','SELECT VIDEO AVI');        if nombre == 0 %If press cancel button, return            set(hObject,'Enable','on');            set(handles.inicio,'Enable','on');            set(handles.parar,'Enable','on');            return        end

## 四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社，2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社，2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社，2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社，2015.
[5]罗敏,刘洞波,文浩轩,陈鑫海,宋丹.基于背景差分法和帧间差分法的车辆运动目标检测[J].湖南工程学院学报(自然科学版). 2019,29(04)

3 备注