【问题标题】:Getting difficulty in tracking of a single vehicle from the video using Matlab?使用 Matlab 从视频中跟踪单个车辆时遇到困难?
【发布时间】:2015-08-09 23:17:20
【问题描述】:

我正在从事一个图像处理项目,该项目基于仅相位重建的重要性。更多信息可以阅读geometrikal在https://dsp.stackexchange.com/questions/16462/how-moving-part-pixel-intensity-values-of-video-frames-becomes-dominant-compared给出的答案

项目有 2 个部分。

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

  2. 对视频中的任何单个移动对象进行跟踪。

现在,我在项目的第一部分相当成功。它的算法是

算法一 建议的方法

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

结果:每帧运动物体的分割掩码

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

  2. 使用二维高斯滤波器平滑当前帧

  3. 使用(Eq.4.1)对整个序列 I(x, y, n) 执行 3D FFT

  4. 使用 3D DFT 的实部和虚部计算相位谱

  5. 使用 (Eq.4.2) 计算重构序列 α(x, y, n)

  6. 对于输入视频中的每一帧,执行步骤 7 到步骤 10 以获得每一帧的分割掩码,并附加步骤 10 的结果分割掩码数组 BW(x,y,n)'

  7. 使用平均滤波器平滑重建的 Î(x, y, n) 帧。

  8. 计算当前帧的平均值

  9. 以均值为阈值将当前帧转化为二值图像

  10. 进行形态学处理,即填充和闭合,得到当前帧运动物体的分割掩码

  11. 结束算法。

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

如图所示,我已经达到了第一列所示的结果。我只达到了第一列的结果。 但我的目标是跟踪单个车辆,如图第二列所示。(我使用 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

【问题讨论】:

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


    【解决方案1】:

    确定要跟踪的对象后,实施卡尔曼滤波器,您将获得所需的跟踪。

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

    【讨论】:

    • 感谢您的反馈,但正如您所观察到的,我已检测到每个视频帧中的所有移动对象。但是现在我想从当前帧中一次检测一个移动对象,并避免其他移动对象。那么我应该在我的 MATLAB 代码中进行哪些更改。?跨度>
    • 啊,这更棘手。你跟踪哪辆车重要吗?如果不是,我记得 matlab 中的 strel 返回一组对象及其像素区域 - 您最初可能会选择最大的一个,然后使用卡尔曼滤波器跟踪那个对象。否则,您需要确定要跟踪的特定汽车的特征并将其实施到您的算法中。
    • 先生,我已经编辑了我的代码并尝试使用有意义的名称尽可能地简化它。现在,如果可能的话,您能否在我的代码中添加卡尔曼滤波器操作并显示对任何车辆的跟踪。那么,您可以在答案框中添加修改后的代码吗?
    • 据我所知,matlab 没有内置的卡尔曼滤波器功能。我提供的 youtube 链接中的 StudentDave 确实有 Matlab code 您可以添加到您的项目中。一旦你有了对象的位置——变量se中列出的对象的中心,你就可以将这些点输入你的过滤器。这个想法是,给定一个位置,您的过滤器会尝试预测对象的下一个位置,然后对下一帧执行校正。如果没有位置,它会猜测对象应该在哪里。
    • 你可以在morphological_closing = imclose(binary_frame,se);这一行之后插入这段代码来调用卡尔曼滤波器。顺便说一句,如果你不知道,这条线morphological_closing=imclearborder(morphological_closing); 实际上更美观,并不需要跟踪。所有对象信息都将在se 中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 2013-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多