need some help with this matlab code...
2 views (last 30 days)
Show older comments
clc
clear all
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);
centroids = centroid(fg);
[thetas rhos] = OrientEccent(fg_smooth, c);
fg_drawn = DrawEllipse(fg,centroids,thetas,rhos)
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');
function drawEllipse
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)) ) = .5;
end
when i run the m file the error i get is
Error in DrawEllipse (line 33)
fg_drawn{frameIndex}( round(y(c)) , round(x(c)) ) = 0.5;
Error in FallDetect (line 50)
fg_drawn = DrawEllipse(fg,centroids,thetas,rhos)
Can someone help me to fix this code please?
2 Comments
Stephen23
on 9 Oct 2015
Please give us the complete error message, not just the bits that you think are interesting. The complete error message is all of the red text.
Answers (2)
Walter Roberson
on 9 Oct 2015
There is nothing in your code that prevents x or y from going negative. Remember, theta and rhos are estimates, and ellipses might be detected near borders.
1 Comment
Image Analyst
on 9 Oct 2015
You can't have fractional indexes. See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_fix_the_error_.22Subscript_indices_must_either_be_real_positive_integers_or_logicals..22.3F
Your x and y, even though you round them, could be zero or negative and all indexes must be natural integers 1,2,3,4,5,......
2 Comments
Image Analyst
on 9 Oct 2015
If that makes the indexes start at 1, and it gives you everything else that you want, then yeah, I guess you're good to go.
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!