フィルターのクリア

need some help with this matlab code...

1 回表示 (過去 30 日間)
Rash Anan
Rash Anan 2015 年 10 月 9 日
コメント済み: Image Analyst 2015 年 10 月 9 日
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 件のコメント
Stephen23
Stephen23 2015 年 10 月 9 日
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.
Rash Anan
Rash Anan 2015 年 10 月 9 日
ohh sorry didn't see the first line.
Attempted to access fg_drawn.%cell(89,0); index must be a positive integer or logical.
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)

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 10 月 9 日
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 件のコメント
Rash Anan
Rash Anan 2015 年 10 月 9 日
編集済み: Rash Anan 2015 年 10 月 9 日
so what i can do is change this line in
fg_drawn{frameIndex}( round(y(c)) , round(x(c)) ) = 0.5;
to something which gives a positive number?
or is there any other way to make this code workable?

サインインしてコメントする。


Image Analyst
Image Analyst 2015 年 10 月 9 日
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 件のコメント
Rash Anan
Rash Anan 2015 年 10 月 9 日
so what i can do is change this line
fg_drawn{frameIndex}( round(y(c)) , round(x(c)) ) = 0.5;
into something like this
fg_drawn{frameIndex}( 1+round(y(c)) , 1+round(x(c)) ) = 0.5;
or is there any other way to make this code workable?
Image Analyst
Image Analyst 2015 年 10 月 9 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeComputer Vision with Simulink についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by