Matlab-vision包学习-Tracking and Motion Estimation-创建Kalman滤波器

这一篇介绍创建Kalman滤波器的matlab函数

函数/Functions

函数名称:configureKalmanFilter

功能:创建Kalman滤波器

语法:kalmanFilter = configureKalmanFilter(MotionModel,InitialLocation,InitialEstimationError,MotionNoise,MeasurementNoise)

其中,MotionModel为运动模型;InitialLocation为运动物体的初始位置;InitialEstimationError为初始估计的位置、速度、加速度(对应匀加速模型)等的方差,在函数中,假设速度和加速度为0;MotionNoise为选择的模型和真实模型的差异;MeasurementNoise为检测到的位置的误差的方差。

close all; 
clear all; 
clc; 
videoReader = vision.VideoFileReader('singleball.avi'); 
videoPlayer = vision.VideoPlayer('Position',[100,100,500,400]); 
foregroundDetector = vision.ForegroundDetector('NumTrainingFrames',10,'InitialVariance',0.05); 
blobAnalyzer = vision.BlobAnalysis('AreaOutputPort',false,'MinimumBlobArea',70); 
kalmanFilter = []; 
isTrackInitialized = false; 
while ~isDone(videoReader)
    colorImage = step(videoReader); 
    foregroundMask = step(foregroundDetector,rgb2gray(colorImage)); 
    detectedLocation = step(blobAnalyzer,foregroundMask); 
    isObjectDetected = size(detectedLocation,1) > 0; 
    if ~isTrackInitialized 
        if isObjectDetected 
            kalmanFilter = configureKalmanFilter('ConstantAcceleration',detectedLocation(1,:),[1 1 1]*1e5,[25,10,10],25); 
            isTrackInitialized = true; 
        end %if 
        label = ''; 
        circle = []; 
    else
        if isObjectDetected
            predict(kalmanFilter); 
            trackedLocation = correct(kalmanFilter,detectedLocation(1,:)); 
            label = 'Corrected'; 
        else
            trackedLocation = predict(kalmanFilter); 
            label = 'Predicted'; 
        end %if 
        circle = [trackedLocation,5]; 
    end %if 
    colorImage = insertObjectAnnotation(colorImage,'circle',...
        circle,label,'Color','red'); 
    step(videoPlayer,colorImage); 
end %while 
release(videoPlayer);
release(videoReader); 


你可能感兴趣的:(Matlab-vision)