CODE TOO SLOW AND SOMETIMES WONT RUN

1 回表示 (過去 30 日間)
Ayesha ayub
Ayesha ayub 2014 年 10 月 19 日
編集済み: per isakson 2014 年 10 月 20 日
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)

回答 (2 件)

per isakson
per isakson 2014 年 10 月 19 日
編集済み: per isakson 2014 年 10 月 19 日

Image Analyst
Image Analyst 2014 年 10 月 19 日
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