使用Matlab从视频跟踪单个车辆时遇到困难?

时间:2015-05-27 17:54:03

标签: matlab image-processing fft phase video-tracking

我正在开展图像处理项目,该项目基于仅相位重建的重要性。有关更多信息,您可以在https://dsp.stackexchange.com/questions/16462/how-moving-part-pixel-intensity-values-of-video-frames-becomes-dominant-compared

中阅读geometrikal给出的答案

项目有两个部分。

  
      
  1. video of Traffic on road检测移动物体(请通过(步骤1)点击播放按钮下载1.47 MB​​视频然后(步骤2)右击视频然后(步骤3) )点击另存为选项)

  2.   
  3. 从视频中跟踪任何单个移动对象。

  4.   

现在,我在项目的第一部分非常成功。算法是

算法1 建议的方法

要求:从视频中提取的输入图像序列I(x,y,n)(其中x和y是图像尺寸,n表示视频中的帧编号)。

结果:每帧移动物体的分割蒙版

  
      
  1. 对于输入视频中的每个帧执行步骤2,将第2步结果附加到结果数组'I(x,y,n)'

  2.   
  3. 使用2D高斯滤波器使当前帧平滑

  4.   
  5. 使用(Eq.4.1)

  6. 对整个序列I(x,y,n)执行3D FFT   
  7. 使用3D DFT的实部和虚部计算相位谱

  8.   
  9. 使用(公式4.2)计算重建序列Î(x,y,n)

  10.   
  11. 对于输入视频中的每个帧执行步骤7到步骤10以获得每个帧的分段掩码并附加步骤10导致得到的分段掩码阵列BW(x,y,n)'

    < / LI>   
  12. 使用平均滤波器平滑重建的Î(x,y,n)帧。

  13.   
  14. 计算当前帧的平均值

  15.   
  16. 使用平均值作为阈值

  17. 将当前帧转换为二进制图像   
  18. 进行形态处理,即填充和关闭,以获得当前帧的移动物体的分段遮罩

  19.   
  20. 结束算法。

  21.   

通过上述算法,我可以从视频中找到所有移动物体。 现在,我想转到第二部分,即从视频中跟踪任何单个移动对象。

enter image description here

如图所示,我已经取得了第1栏中显示的结果。我已经达到了第1列的结果。 但我的目标是跟踪单个车辆,如图中第二列所示。(我已使用Photoshop在第二列显示结果)

那么有人可以帮助我吗?

 tic
clc;
clear all;
close all;

%read video file
video = VideoReader('D:\dvd\Matlab code\test videos\5.mp4');

T= video.NumberOfFrames  ;           %number of frames%

frameHeight = video.Height;          %frame height

frameWidth = video.Width ;           %frameWidth

get(video);                          %return graphics properties of video


i=1;

for t=300:15:550  %select frames between 300 to 550 with interval of 15 from the video  
    frame_x(:,:,:,i)= read(video, t); 
    frame_y=frame_x(:,:,:,i);

    %figure,
    %imshow(f1),title(['test frames :' num2str(i)]);
    frame_z=rgb2gray(frame_y);                 %convert each colour frame into gray

    frame_m(:,:,:,i)=frame_y; %Store colour frames in the frame_m array 

    %Perform Gaussian Filtering
    h1=(1/8)*(1/8)*[1 3 3 1]'*[1 3 3 1]  ;   % 4*4 Gaussian Kernel  
    convn=conv2(frame_z,h1,'same');

    g1=uint8(convn);


    Filtered_Image_Array(:,:,i)=g1; %Store filtered images into an array
    i=i+1;
end

%Apply 3-D Fourier Transform on video sequences
f_transform=fftn(Filtered_Image_Array);

%Compute phase spectrum array from f_transform
phase_spectrum_array =exp(1j*angle(f_transform));

%Apply 3-D Inverse Fourier Transform on phase spectrum array and
%reconstruct the frames
reconstructed_frame_array=(ifftn(phase_spectrum_array));


k=i;

i=1;
for t=1:k-1

    %Smooth the reconstructed frame of Î(x, y, n) using the averaging filter.
    Reconstructed_frame_magnitude=abs(reconstructed_frame_array(:,:,t));  
    H = fspecial('disk',4);
    circular_avg(:,:,t) = imfilter(Reconstructed_frame_magnitude,H);


    %Convert the current frame into binary image using mean value as the threshold
    mean_value=mean2(circular_avg(:,:,t));  
    binary_frame = im2bw(circular_avg(:,:,t),1.6*mean_value);


    %Perform Morphological operations
    se = strel('square',3);
    morphological_closing = imclose(binary_frame,se); 
    morphological_closing=imclearborder(morphological_closing); %clear noise present at the borders of the frames


    %Superimpose segmented masks on it's respective frames to obtain moving
    %objects
    moving_object_frame = frame_m(:,:,:,i);
    moving_object_frame(morphological_closing) = 255;  
    figure,
    imshow(moving_object_frame,[]), title(['Moving objects in Frame :' num2str(i)]);

 i=i+1;
end
toc

1 个答案:

答案 0 :(得分:0)

一旦您确定要跟踪的对象实施卡尔曼滤波器,您就可以获得所需的跟踪。

那里有相当多的资源,但是如果你想手动完成,我建议你在YouTube上使用StudentDave的解释非常好。 https://www.youtube.com/watch?v=FkCT_LV9Syk