Game Development Reference

In-Depth Information

Hardcoding a pattern for the computer to look for would result in a very narrow set of

recognition criteria. Therefore, computer-vision algorithms rely on a system of training

rather than hard programming. Specifically, they use
cascade classifier training
.

The training process works well but requires a large image set. Typical examples require

6,000 negative images and 1,500 positive images. The negative images are commonly

called background images. When training the algorithm, you take 1,200 of your positive

images and draw selection rectangles around the object you are trying to detect. The

computer learns that the pattern in the selection rectangles you've given it is one to be

identified. This will take the average computer a long, long time. The remaining images

are used for testing to ensure that your algorithm has satisfactory accuracy in detecting

the patterns you've shown it. The larger the sample set, including different lighting, the

more accurate the system will be. Once the algorithm is trained to detect a particular

object, all you need is the training file—usually an
.xml
file—to share that training with

another computer.

Numerical Differentiation

As previously noted, there are many ways to collect optical tracking data, but since we

are focusing on the physics aspects, we'll now talk about how to process the data to get

meaningfully physical simulation. By combining object detection with depth sensing,

we can detect and then track an object as it moves in the camera's field of vision. Let's

assume that you have used the frame rate or internal clock to generate data of the fol‐

lowing format:

{(x[i],y[i],z[i],t[i]),(x[i+1],y[i+1],z[i+1],t[i+1]) ,

(x[i+2],y[i+2],z[i+2],t[i+2]), ...}

Now, a single data point consisting of three coordinates and a timestamp doesn't allow

us to determine what is going on with an object's velocity or acceleration. However, as

the camera is supplying new position data at around 20-30 Hz, we will generate a time

history of position or displacement. Using techniques similar to the numerical integra‐

tion we used to take acceleration and turn it into velocities and then turn those velocities

into position in earlier chapters, we can apply numerical differentiation to accomplish

the reverse. Specifically, we can use the finite difference method.

For velocity, we need a first-order finite difference numerical differentiation scheme.

Because we know the current data point and the previous data point, we are looking

backward in time to get the current position. This is known as the
backward difference

scheme
. In general, the backward difference is given by:

f'(x) = lim h→0 (f(x+h) - f(x)) / h

We must use the backward difference for the first-order differentiation, as we know only

the present position and past positions. In our case,
h
is the difference in time between