need some help with this matlab code...
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Stephen23
le 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.
Réponses (2)
Walter Roberson
le 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 commentaire
Image Analyst
le 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 commentaires
Image Analyst
le 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.
Voir également
Catégories
En savoir plus sur Computer Vision with Simulink dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!