嗨我在提取前景后尝试在检测到的blob周围绘制一个椭圆。在这里我附加了我的代码,但是当我尝试绘制椭圆时它会出错。如果有人可以帮我修改这段代码,那将是一个很大的帮助。
function fg_drawn = DrawEllipse(fg,centroids,thetas,rhos)
fg_drawn = fg;
NumOfFrames = length(fg);
t = 0:.01:2*pi;
for frameIndex = 1:NumOfFrames
theta = thetas(frameIndex);
%TO BE MODIFIED
b = 60;
a = b / rhos(frameIndex);
h = centroids(frameIndex,1);
k = centroids(frameIndex,2);
x = h + cos(theta)*(a*cos(t)) - sin(theta)*(b*sin(t));
y = k + sin(theta)*(a*cos(t)) + cos(theta)*(b*sin(t));
for c = 1:length(x)
fg_drawn{frameIndex}(round(y(c)) , round(x(c)) ) = 0.5;
end
fg_drawn{frameIndex}( round(centroids(frameIndex,2)) , round(centroids(frameIndex,1)) ) = 0.5;
end
m file
clc
clear all
disp('Loading Video..');
v = VideoReader('test.avi');
video1 = read(v,[10 inf]);
video1 = mat2cell(video1, size(video1,1), size(video1,2), size(video1,3), ones(1,size(video1,4)) );
disp('Extracting Foreground..');
fg = extractForeground(video1,30,4,0);
disp('Eliminating Noise from Foreground..');
fg_smooth=detectBlob(fg);
disp('Evaluating Motion History Image of the video..');
motion_history = MHI(fg_smooth);
disp('Determining Ellipse Statistical Properties..');
**c = centroid(fg_smooth);
[thetas rhos] = OrientEccent(fg, c);**
fg_drawn = DrawEllipse(fg_smooth,c,thetas,rhos)
[fg_drawn,thetas,rhos] = EllipseMain(fg)
figure(1);
imshow(fg{22})
title('Foreground Extraction');
figure(2);
imshow(fg_smooth{22})
title('Noise Elimination');
figure(3);
imshow(fg_drawn{22})
title('Ellipse Detection');
T=15;
frameDisp = motion_history{22};
frameDisp = double(frameDisp);
frameDisp = frameDisp ./ T;
figure(4);
imshow(frameDisp)
title('MHI Image');
disp('Analyzing Statistics for Video..');
[sigma_t sigma_r c_motion] = statistics(thetas, rhos, motion_history);
figure(5)
subplot(2,2,1);
plot(sigma_t);
title('Theta Std Dev Values');
subplot(2,2,2);
plot(sigma_r);
title('Rho Std Dev Values');
subplot(2,2,3);
plot(c_motion);
title('C Motion Values');
maxTheta = max(sigma_t);
gaussianFilter = fspecial('gaussian', [9, 9], 3.8);
for t = 1:(length(sigma_t)-5)
if(c_motion(t) > 0.65 && sigma_t(t) >= 0.9*maxTheta)
disp('FALL DETECTED!!');
figure(6);
imshow(imfilter(video1{t+5}, gaussianFilter));
break;
end
end
disp('Done!!!');
当我运行此代码时,我得到的错误是 尝试访问fg_drawn。%cell(134,0); index必须是正整数或逻辑。 DrawEllipse出错(第33行) fg_drawn {frameIndex}(round(y(c)),round(x(c)))= 0.5;
因为错误本身表示索引必须是正整数,我尝试了几种方法来防止x或y变为负数。但没有任何效果。我仍然无法在检测到的斑点周围得到椭圆图。