Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to speed up tracking object code ????

Subject: how to speed up tracking object code ????

From: No0o0oR

Date: 8 May, 2010 20:18:05

Message: 1 of 8

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

Subject: how to speed up tracking object code ????

From: No0o0oR

Date: 9 May, 2010 16:03:04

Message: 2 of 8

"No0o0oR " <n.khaznadar@live.com> wrote in message <hs4gtt$171$1@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 !!!!!!!!!!!!!!

Subject: how to speed up tracking object code ????

From: Yair Altman

Date: 9 May, 2010 16:34:04

Message: 3 of 8

"No0o0oR " <n.khaznadar@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.

Subject: how to speed up tracking object code ????

From: dpb

Date: 9 May, 2010 16:58:29

Message: 4 of 8

No0o0oR wrote:
...

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

expletive_word_of_choice'ing off, apparently... :(

<plonk>

--

Subject: how to speed up tracking object code ????

From: Steven Lord

Date: 10 May, 2010 02:56:08

Message: 5 of 8


"No0o0oR " <n.khaznadar@live.com> wrote in message
news:hs6mbo$m94$1@fred.mathworks.com...
> "No0o0oR " <n.khaznadar@live.com> wrote in message
> <hs4gtt$171$1@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@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: how to speed up tracking object code ????

From: No0o0oR

Date: 14 May, 2010 19:07:20

Message: 6 of 8

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <hs6o5s$h51$1@fred.mathworks.com>...
> "No0o0oR " <n.khaznadar@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.


OMG !!! i am really sorry i really didn't mean any harm in my sentence :S .. i am very sorry please accept my apology .. and i really didn't notice for the time that its weekend :-) ... sorry again i really just was ambitious for getting answers for you because of your expertise and i didn't meant any harm ... sorry again :-) ..

  

Subject: how to speed up tracking object code ????

From: No0o0oR

Date: 14 May, 2010 19:09:06

Message: 7 of 8

dpb <none@non.net> wrote in message <hs6pn2$gvk$2@news.eternal-september.org>...
> No0o0oR wrote:
> ...
>
> > where are you guys !!!!!!!!!!!!!!
>
> expletive_word_of_choice'ing off, apparently... :(
>
> <plonk>
>
> --

sorry i didn't mean any harm !

Subject: how to speed up tracking object code ????

From: No0o0oR

Date: 14 May, 2010 19:13:06

Message: 8 of 8

"Steven Lord" <slord@mathworks.com> wrote in message <hs7sk1$b1m$1@fred.mathworks.com>...
>
> "No0o0oR " <n.khaznadar@live.com> wrote in message
> news:hs6mbo$m94$1@fred.mathworks.com...
> > "No0o0oR " <n.khaznadar@live.com> wrote in message
> > <hs4gtt$171$1@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@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

thanks for your answering Mr.Steve i really appreciate it and i am sorry for my tone i didn't want it to be understood in that way and i have to submit my project soon sorry for any disturbance i did ...
please accept my apology .

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us