# problem with real time detection

1 visualización (últimos 30 días)
Ayesha ayub el 9 de Oct. de 2014
Respondida: Image Analyst el 9 de Oct. de 2014
i made a motion detection code :
clear all
threshold= 35;
first_frame_gray=rgb2gray(first_frame);
total_frames= video.NumberOfFrames;
[row,column,page]=size(first_frame);
dummy_matrix = zeros(row,column);
for i=2:total_frames
current_frame_gray=rgb2gray(current_frame);
frame_difference=imabsdiff(current_frame_gray,first_frame_gray);
for nr=1:row
for nc=1:column
if ((frame_difference(nr,nc) > threshold))
dummy_matrix(nr,nc) = frame_difference(nr,nc);
else
dummy_matrix(nr,nc) = 0;
end
end
end
first_frame_gray= current_frame_gray;
figure(1)
subplot(2,1,1)
imshow(current_frame)
subplot(2,1,2)
imshow(uint8(dummy_matrix))
end
.........................................
now i convert it to real time here is my code for real time:
clear all;
threshold=35; i=1;
video = videoinput('winvideo',1,'YUY2_1280x1024'); first_frame=getsnapshot(video); first_frame_gray=rgb2gray(first_frame);
[row,column,page]=size(first_frame); dummy_matrix = zeros(row,column);
current_frame=getsnapshot(video);
current_frame_gray = rgb2gray(current_frame);
frame_difference=imabsdiff(current_frame_gray,first_frame_gray);
for nr=1:row
for nc=1:column
if (frame_difference(nr,nc) > threshold)
dummy_matrix(nr,nc) = frame_difference(nr,nc);
else
dummy_matrix(nr,nc) = 0;
end
end
end
first_frame_gray= current_frame_gray;
preview(video);
figure(1)
subplot(2,1,1)
imshow(current_frame)
subplot(2,1,2)
imshow(uint8(dummy_matrix))
Movie(i) = im2frame(uint8(dummy_matrix),gray);
i=i+1;
the problem is my code run once and capture only first frame . if i use while loop then the code rune forever and to stop it i have to close matlab plus its really slow.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Image Analyst el 9 de Oct. de 2014
First of all, binarize that pair of for loops like this
binaryImage = frame_difference(nr,nc) <= threshold;
dummy_matrix = frame_difference;
dummy_matrix(binaryImage) = 0;
anyway, I see no other looping in your code. Why do you think it should loop? You have no for or while construction to make it loop. You need to put in code to make it loop if you want it to loop.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Point Grey Hardware en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by