Borrar filtros
Borrar filtros

CODE TOO SLOW AND SOMETIMES WONT RUN

2 visualizaciones (últimos 30 días)
Ayesha ayub
Ayesha ayub el 19 de Oct. de 2014
Editada: per isakson el 20 de Oct. de 2014
i have made a code for motion detection in real time but its too slow and sometimes wont even run why?
here's my code :
clear all
clc
imaqmem(999999999);
threshold= 0.5;
frame=0;
video= videoinput('winvideo',1,'YUY2_1280x1024'); %creating video object
start(video) %initiliazing video
first_frame = getsnapshot(video);
first_frame_gray=rgb2gray(first_frame);
[row,column,page]=size(first_frame);
dummy_matrix = zeros(row,column);
while(frame<50)
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 fr_diff > thresh then that pixel is in foreground
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;
subplot(2,1,1)
imshow(current_frame)
subplot(2,1,2)
imshow(uint8(dummy_matrix))
frame=frame+1;
end
flushdata(video)
delete(video)

Respuestas (2)

per isakson
per isakson el 19 de Oct. de 2014
Editada: per isakson el 19 de Oct. de 2014

Image Analyst
Image Analyst el 19 de Oct. de 2014
I do frame differencing in my demo. Run it and compare how it works to how yours works. The only difference is I get from frames from a video file instead of a camera, and I subtract the current frame from the average of several other frames instead of the latest one.

Community Treasure Hunt

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

Start Hunting!

Translated by