Streaming camera frames for template matching

Template matching is a machine-learning technique to find areas of an image that match a given template image. We will apply template matching to every frame of a real-time video stream to locate an image.

Getting ready

Install the OpenCV and c2hs toolkits:

$ sudo apt-get install c2hs libopencv-dev

Install the CV library from cabal. Be sure to include the –fopencv24 or –fopencv23 parameter depending on which version of OpenCV is installed:

$ cabal install CV -fopencv24

Also, create a small template image. In this recipe, we use an image of Lena, which is usually used in many image-processing experiments. We name this image file lena.png:

How to do it…

In a new file, Main.hs, start with these steps:

  1. Import ...

Get Haskell Data Analysis Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.