CODE TOO SLOW AND SOMETIMES WONT RUN
1 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
回答(2 个)
per isakson
2014-10-19
编辑:per isakson
2014-10-19
See:
The debugging tools of Matlab are good! Here are some links on debugging in Matlab
0 个评论
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!