Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
OpenCV 3.0 Computer Vision with Java

You're reading from  OpenCV 3.0 Computer Vision with Java

Product type Book
Published in Jul 2015
Publisher
ISBN-13 9781783283972
Pages 174 pages
Edition 1st Edition
Languages
Author (1):
Daniel Lelis Baggio Daniel Lelis Baggio
Profile icon Daniel Lelis Baggio

Table of Contents (15) Chapters

OpenCV 3.0 Computer Vision with Java
Credits
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
Setting Up OpenCV for Java Handling Matrices, Files, Cameras, and GUIs Image Filters and Morphological Operators Image Transforms Object Detection Using Ada Boost and Haar Cascades Detecting Foreground and Background Regions and Depth with a Kinect Device OpenCV on the Server Side Index

Frame differencing


It should be straightforward to think of a simple background subtraction in order to retrieve foreground objects. A simple solution could look similar to the following line of code:

Core.absdiff(backgroundImage,inputImage , foregroundImage);

This function simply subtracts each pixel of backgroundImage from inputImage and writes its absolute value in foregroundImage. As long as we have initialized the background to backgroundImage and we have that clear from objects, this could work as a simple solution.

Here follows the background subtraction video processor code:

public class AbsDifferenceBackground implements VideoProcessor {
  private Mat backgroundImage;

  public AbsDifferenceBackground(Mat backgroundImage) {
    this.backgroundImage = backgroundImage;
  }

  public Mat process(Mat inputImage) {
    Mat foregroundImage = new Mat();
    Core.absdiff(backgroundImage,inputImage , foregroundImage);
    return foregroundImage;
  }

}

The main method, process, is really simple...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}