【发布时间】:2014-06-22 10:58:25
【问题描述】:
我有兴趣了解如何获取用于检测视频中的斑点的边界框。我的代码涉及背景减法,我使用的是简单的函数:
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
在此之后,我正在寻找可以在 blob 周围连续绘制边界框的代码。
【问题讨论】:
标签: image matlab image-processing video-processing bounding-box