我正在从事一个图像处理项目,该项目基于仅相位重建的重要性。有关更多信息,您可以在https://dsp.stackexchange.com/questions/16462/how-moving-part-pixel-intensity-values-of-video-frames-becomes-dominant-compared中阅读 geometrikal 给出的答案
项目有 2 个部分。
从道路交通视频中检测移动物体(请通过(步骤1)单击播放按钮然后(步骤2)右键单击视频然后(步骤3)单击另存为选项下载1.47 MB的视频)
跟踪视频中的任何单个移动对象。
现在,我在项目的第一部分非常成功。它的算法是
算法 1 建议的方法
要求:从视频中提取的输入图像序列 I(x, y, n)(其中 x 和 y 是图像尺寸,n 表示视频中的帧数)。
结果:每帧运动物体的分割掩码
对于输入视频中的每一帧,执行第 2 步,将第 2 步结果附加到结果数组 'I(x, y, n)'</p>
使用 2D 高斯滤波器平滑当前帧
使用(Eq.4.1)对整个序列 I(x, y, n) 执行 3D FFT
使用 3D DFT 的实部和虚部计算相位谱
使用 (Eq.4.2) 计算重构序列 α(x, y, n)
对于输入视频中的每一帧,执行步骤 7 到步骤 10 以获得每一帧的分割掩码,并将步骤 10 附加到生成的分割掩码数组 BW(x,y,n)'</p>
使用平均滤波器平滑重建的 Î(x, y, n) 帧。
计算当前帧的平均值
以平均值为阈值将当前帧转换为二值图像
进行形态学处理,即填充和闭合,得到当前帧运动物体的分割掩码
结束算法。
使用上述算法,我可以从视频中找到所有移动对象。现在,我想转到第二部分,即对视频中的任何单个移动对象进行跟踪。
如图所示,我已经达到了第一列所示的结果。我只达到了第一列的结果。但我的目标是跟踪单个车辆,如图第二列所示。(我使用 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