From: No0o0oR on
hello friends,

i am doing a project regarding tracking objects using real time video and i am having some issues. it seems that the tracking slows down after a while and i don't know how to track multiple objects in the video i am only able to detect one object at a time..

please any suggestions on how to speed up my tracking and how to be able to track multiple objects ..

this is my code ..


vidobj=videoinput('winvideo',1, 'YUY2_320x240');
triggerconfig(vidobj, 'manual');

frame = getsnapshot(vidobj);
bg=rgb2gray(frame);
fr_size = size(frame);
width = fr_size(2);
height = fr_size(1);

question=9;
while (question ~='q')

frame1 = getsnapshot(vidobj);
frame1_bw = rgb2gray(frame1);

fr_diff = abs(double(frame1_bw) - double(bg));

x1=0;
x2=width;
y1=0;
y2=height;
fg = zeros(height, width);
xmid=0;
ymid=0;
for j=1:width % if fr_diff > thresh pixel in foreground
for k=1:height
if ((fr_diff(k,j) > 25)) %check if the pixel is moving or fixed
fg(k,j) = 255;

% detect rectangle coordinates
if(j<x2)
x2=j;
end
x1=j; %min x
y1=k; %max y
if(k<y2)
y2=k;
end

% shooting point coordinates **************************
xmid=(x1+x2)/2; % x coordinate for the shooting point
ymid=(y1+y2)/2; % y coordinate for the shooting point

w=x1-x2; % width of the contour rectangle
h=y1-y2; % height of the contour rectangle
%******************************************************
% to avoid having width and height = 0 and get an error
if(w<1)
w=1;
end
if(h<1)
h=1;
end
%******************************************************
% if the object went out ro the region, center the sniper
if((xmid<2)||(xmid>width))
xmid=width/2;
ymid=height/2;
end

if((ymid<2)||(ymid>height))
xmid=width/2;
ymid=height/2;
end
%********************************************************

else
fg(k,j) = 0;

end
end
end

imshow(frame1_bw)
hold on;
plot(xmid,ymid,'rx','MarkerSize',10) % draw shooting point

rect=rectangle('Position', [x2 y2 w h]); % draw contour rectangle
set(rect,'EdgeColor','y','LineWidth',2);

uicontrol('String', 'Start',...
'Callback', 'start(vidobj)',...
'Units', 'normalized',...
'Position',[0 0 0.15 0.07]);
uicontrol('String', 'Stop',...
'Callback', 'stop(vidobj)',...
'Units', 'normalized',...
'Position',[0.17 0 0.15 0.07]);



end
From: No0o0oR on
"No0o0oR " <n.khaznadar(a)live.com> wrote in message <hs4gtt$171$1(a)fred.mathworks.com>...
> hello friends,
>
> i am doing a project regarding tracking objects using real time video and i am having some issues. it seems that the tracking slows down after a while and i don't know how to track multiple objects in the video i am only able to detect one object at a time..
>
> please any suggestions on how to speed up my tracking and how to be able to track multiple objects ..
>
> this is my code ..
>
>
> vidobj=videoinput('winvideo',1, 'YUY2_320x240');
> triggerconfig(vidobj, 'manual');
>
> frame = getsnapshot(vidobj);
> bg=rgb2gray(frame);
> fr_size = size(frame);
> width = fr_size(2);
> height = fr_size(1);
>
> question=9;
> while (question ~='q')
>
> frame1 = getsnapshot(vidobj);
> frame1_bw = rgb2gray(frame1);
>
> fr_diff = abs(double(frame1_bw) - double(bg));
>
> x1=0;
> x2=width;
> y1=0;
> y2=height;
> fg = zeros(height, width);
> xmid=0;
> ymid=0;
> for j=1:width % if fr_diff > thresh pixel in foreground
> for k=1:height
> if ((fr_diff(k,j) > 25)) %check if the pixel is moving or fixed
> fg(k,j) = 255;
>
> % detect rectangle coordinates
> if(j<x2)
> x2=j;
> end
> x1=j; %min x
> y1=k; %max y
> if(k<y2)
> y2=k;
> end
>
> % shooting point coordinates **************************
> xmid=(x1+x2)/2; % x coordinate for the shooting point
> ymid=(y1+y2)/2; % y coordinate for the shooting point
>
> w=x1-x2; % width of the contour rectangle
> h=y1-y2; % height of the contour rectangle
> %******************************************************
> % to avoid having width and height = 0 and get an error
> if(w<1)
> w=1;
> end
> if(h<1)
> h=1;
> end
> %******************************************************
> % if the object went out ro the region, center the sniper
> if((xmid<2)||(xmid>width))
> xmid=width/2;
> ymid=height/2;
> end
>
> if((ymid<2)||(ymid>height))
> xmid=width/2;
> ymid=height/2;
> end
> %********************************************************
>
> else
> fg(k,j) = 0;
>
> end
> end
> end
>
> imshow(frame1_bw)
> hold on;
> plot(xmid,ymid,'rx','MarkerSize',10) % draw shooting point
>
> rect=rectangle('Position', [x2 y2 w h]); % draw contour rectangle
> set(rect,'EdgeColor','y','LineWidth',2);
>
> uicontrol('String', 'Start',...
> 'Callback', 'start(vidobj)',...
> 'Units', 'normalized',...
> 'Position',[0 0 0.15 0.07]);
> uicontrol('String', 'Stop',...
> 'Callback', 'stop(vidobj)',...
> 'Units', 'normalized',...
> 'Position',[0.17 0 0.15 0.07]);
>
>
>
> end






where are you guys !!!!!!!!!!!!!!
From: Yair Altman on
"No0o0oR " <n.khaznadar(a)live.com> wrote in message

> where are you guys !!!!!!!!!!!!!!

We're all waiting for your $1000 check before answering...

Seriously, who do you think you are, taking this tone?! Less than 24 hours of *WEEKEND* have passed since you posted the question - do you think we have no life and are just waiting around to answer questions like yours on our free weekend time?

When you start treating other people's time and effort respectfully, perhaps you will get respectful answers in return.
From: dpb on
No0o0oR wrote:
....

> where are you guys !!!!!!!!!!!!!!

expletive_word_of_choice'ing off, apparently... :(

<plonk>

--
From: Steven Lord on

"No0o0oR " <n.khaznadar(a)live.com> wrote in message
news:hs6mbo$m94$1(a)fred.mathworks.com...
> "No0o0oR " <n.khaznadar(a)live.com> wrote in message
> <hs4gtt$171$1(a)fred.mathworks.com>...

*snip*

> where are you guys !!!!!!!!!!!!!!

Relaxing and enjoying the weekend. Here in Natick at least, it's been an
okay weekend (Saturday was a bit wet, and today was windy, but it's been
worse in the past month.)

Anyway, I recommend running your code in the Profiler:

help profile

to locate the bottlenecks, then work on optimizing them. If you have Code
Analyzer warnings in your code (particularly if they're in those sections
the Profiler indicated are the bottlenecks) then fix them.

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_env/brqxeeu-151.html

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


 |  Next  |  Last
Pages: 1 2
Prev: Plot problems
Next: Transfer function with e^-T