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!