real time image processing (while loop)

1 回表示 (過去 30 日間)
naim
naim 2014 年 2 月 15 日
回答済み: naim 2014 年 2 月 15 日
hello im tring to write a real time motion detection matlab code but i have a weird problem with the while loop this is a part of the code
im=getsnapshot(vid);
while(i<m)
flag=0;
pause(.1)
im2=getsnapshot(vid);
im=imcrop(im,[mesh(i,1) mesh(i,2) (mesh(i,3)-mesh(i,1)) (mesh(i,4)-mesh(i,2))]);
im2=imcrop(im2,[mesh(i,1) mesh(i,2) (mesh(i,3)-mesh(i,1)) (mesh(i,4)-mesh(i,2))]);
im=rgb2gray(im);
im2=rgb2gray(im2);
fr_diff = abs(double(im) - double(im2));
but i get this error
Error using rgb2gray>parse_inputs (line 81) MAP must be a m x 3 array.
Error in rgb2gray (line 35) X = parse_inputs(varargin{:});
Error in testing (line 27) im=rgb2gray(im);
when the line im=getsnapshot(vid); is inside the loop it doesn't give an error!!!!

採用された回答

Image Analyst
Image Analyst 2014 年 2 月 15 日
What does
whos im
size(im)
say? It might be more robust to do this
[rows, columns, numberOfColorChannels] = size(im);
if numberOfColorChannels > 1
im = rgb2gray(im); % Convert color to gray scale.
end

その他の回答 (2 件)

naim
naim 2014 年 2 月 15 日
it is an rgb image when i change the code to
while(i<1)
im=getsnapshot(vid);
.
.
.
the code works with no errors O_o

naim
naim 2014 年 2 月 15 日
ok i got it now i save the gray croped image in the same matrex (im) -.- XD ok thanks man :D

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by