CODE TOO SLOW AND SOMETIMES WONT RUN

1 visualizzazione (ultimi 30 giorni)
Ayesha ayub
Ayesha ayub il 19 Ott 2014
Modificato: per isakson il 20 Ott 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)

Risposte (2)

per isakson
per isakson il 19 Ott 2014
Modificato: per isakson il 19 Ott 2014

Image Analyst
Image Analyst il 19 Ott 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