2

I'm trying to track a ball in a video in Matlab by using a template and this function from the Image Processing Toolbox:

LOC = step(H,I,T,ROI) computes the [x,y] location of the best template match, LOC, in the specified region of interest, ROI.

I start with a simple ROI that takes over the whole frame and the code successfully tracks the ball but it's very slow because the ROI is still set as the whole image.

Basically, I want to take the x and y coordinates of LOC (the location of the ball) and update the ROI so that it's a square over the LOC, then roll the next frame and look for the ball within the new compact ROI. This will leave a much smaller ROI for the code to look for the ball and hopefully speeds up the code.

How do I extract the x/y coordinates of LOC and use them to create a new ROI within the area?

Dima
  • 38,860
  • 14
  • 75
  • 115
A.Sully
  • 21
  • 4

1 Answers1

1

From the documentation :

The LOC [x y] coordinates correspond to the center of the template.

Example usage:

% Find the [x y] coordinates of the chip's center
  Loc=step(htm,Igray,T);  
GilLevi
  • 2,117
  • 5
  • 22
  • 38
  • I'm pretty sure LOC corresponds to the center of the tracked ball in the bigger image, not the template. When I run the code I get many different LOC values, x and y. I want to use them to find Range of Interest. Let's say the LOC is x and y. ROI = [ x-20 y-20 x+20 y+20]; -will give me a square around the LOC. How do I use the LOC values? is it like "LOC[1]" or something to get x? (This might be more of a matrices question, sorry bout that) – A.Sully May 04 '14 at 15:02
  • I think LOC(1) = x, LOC(2)=y (or the other way around). – GilLevi May 04 '14 at 18:39