Book Image

OpenCV for Secret Agents

By : Joseph Howse
Book Image

OpenCV for Secret Agents

By: Joseph Howse

Overview of this book

Table of Contents (15 chapters)
OpenCV for Secret Agents
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Estimating distances (a cheap approach)


Suppose we have an object sitting in front of a pinhole camera. Regardless of the distance between the camera and object, the following equation holds true:

objectSizeInImage / focalLength = objectSizeInReality / distance

We might use any unit (such as pixels) in the equation's left-hand side and any unit (such as meters) in its right-hand side. (On each side of the equation, the division cancels the unit.) Moreover, we can define the object's size based on anything linear that we can detect in the image, such as the diameter of a detected blob or the width of a detected face rectangle.

Let's rearrange the equation to illustrate that the distance to the object is inversely proportional to the object's size in the image:

distance = focalLength * objectSizeInReality / objectSizeInImage

Let's assume that the object's real size and the camera's focal length are constant. Consider the following arrangement, which isolates the pair of constants on the right...