Our goal in this chapter is to add image tracking to Second Sight
. We will train the app to recognize certain arbitrary, rectangular images—for example, paintings—and to determine their pose in a 2D projection. The app will draw an outline around a tracked image when it appears in the camera feed. All of the tracking and drawing is done using OpenCV rather than other Android libraries.
The complete Eclipse project for this chapter can be downloaded from my website at http://nummist.com/opencv/5206_04.zip.
For this chapter, we need to add just one new class, com.nummist.secondsight.filters.ar.ImageDetectionFilter
. We also need to add some resource files, that is, the images that we want to track. Download the images from http://nummist.com/opencv/5206_04_images.zip, unzip them, and put them in the project's res/drawable-nodpi
folder.
These images are famous paintings by a Dutch artist named Vincent van Gogh and an Indian artist named Basawan. Our tracker will work well with these images because they contain many high-contrast details, without much repetition of patterns. Thus, there is something distinctive to track in most of the parts of each image. For example, here is one of Basawan's paintings, Akbar Hunting with Cheetahs:
And here is one of Van Gogh's paintings, The Starry Night: