OpenCV for Secret Agents
上QQ阅读APP看书,第一时间看更新

Planning the Luxocator app

This chapter uses Python. Being a high-level interpreted language with great third-party libraries for numeric and scientific computing, Python lets us focus on the functionality of the system rather than implementing subsystem details. For our first project, such a high-level perspective is precisely what we need.

Let's take an overview of Luxocator's functionality and our choice of Python libraries that support this functionality. Like many computer vision applications, Luxocator has 6 basic steps:

  1. Acquire a static set of reference images: For Luxocator, we (the developers) will choose certain images that we will deem to be "Luxury, indoor" scenes, other images that we will consider as "Stalinist, indoor" scenes, and so on. We will load these images into memory.
  2. Train a model based on the reference images: For Luxocator, our model will describe each image in terms of its normalized color histogram, that is, the distribution of colors across the image's pixels. We will use OpenCV and NumPy to perform the calculations.
  3. Store the results of the training: For Luxocator, we will use SciPy to compress the reference histograms and write/read them to/from the disk.
  4. Acquire a dynamic set of query images: For Luxocator, we will acquire query images using the Bing Search API via a Python wrapper. We will also use the Requests library to download the full resolution images.
  5. Compare the query images with the reference images: For Luxocator, we will compare each query image and each reference image based on the intersection of their histograms. We will then make a classification based on the average results of these comparisons. We will use NumPy to perform the calculations.
  6. Present the results of the comparison: For Luxocator, we will provide a GUI to initiate a search and navigate the results. This cross-platform GUI will be developed in wxPython. A classification label, such as "Stalinist, exterior", will be shown below each image. See the following screenshot:
    Planning the Luxocator app

Optionally, we will use PyInstaller to build Luxocator so that it can be deployed to users who do not have Python or the aforementioned libraries. However, remember that you might need to do extra troubleshooting of your own to make PyInstaller work in some environments, including Raspberry Pi or other ARM devices.