我有興趣瞭解如何獲取用於檢測視頻中的斑點的邊界框。我的代碼涉及背景減除,我使用簡單功能:如何在Matlab中繪製視頻的邊界框
clc
clear all
close all
m=0; n=0;
readerobj = mmreader('dt2.wmv');% dt2 is my sample fixed cam video
vidframes = read(readerobj);
thresh = 15;
bg = read(readerobj,1);
bg_bw = double(rgb2gray(bg));
fr_size = size(vidframes);
width = fr_size(2);
height = fr_size(1);
fg = zeros(height, width);
numFrames=get(readerobj,'NumberofFrames');
for k = 1 : numFrames
mov(k).cdata = vidframes(:,:,:,k);
mov(k).colormap = [];
end
movie(mov, 1, readerobj.FrameRate)
a=1; x=[0 0]; p=0; c=0;
for i = 2:2:numFrames
fr = read(readerobj,i);
fg = zeros(size(fr));
fr_bw = rgb2gray(fr);
fr_diff = abs(double(fr_bw) - double(bg_bw));
for j=1:width
for k=1:height
if ((fr_diff(k,j) > thresh))
fg(k,j) = 255; %fr_bw(k,j)
else
fg(k,j) = 0;
end
if (fr_bw(k,j) > bg_bw(k,j))
bg_bw(k,j) = bg_bw(k,j) + 1;
elseif (fr_bw(k,j) < bg_bw(k,j))
bg_bw(k,j) = bg_bw(k,j) - 1;
end
end
%median filter to remove noise
L=medfilt2(fg,[5,5]);
%removing small parts less than threshold area
final=bwareaopen(L,4000);
%filling the holes
ifill=imfill(final,'holes');
%to know the number of connected objects
[Ilabel num]=bwlabel(ifill);
if (num>=1)
%region properties of the image
Iprops=regionprops(Ilabel);
%extracting the bounding box properties
Ibox=[Iprops.BoundingBox];
end
% ????? What do I do next?
end
在此之後,我要尋找的代碼,會不斷周圍畫團塊邊界框。