Book Image

Haskell Data Analysis Cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis Cookbook

By: Nishant Shukla

Overview of this book

Table of Contents (19 chapters)
Haskell Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 the relevant libraries:

    {-#LANGUAGE ScopedTypeVariables#-}
    module Main where
    import CV.Image (loadImage, rgbToGray, getSize)
    import CV.Video (captureFromCam, streamFromVideo)
    import Utils.Stream (runStream_, takeWhileS, sideEffect)
    import CV.HighGUI...