Book Image

OpenCV 3.0 Computer Vision with Java

By : Daniel Lelis Baggio
Book Image

OpenCV 3.0 Computer Vision with Java

By: Daniel Lelis Baggio

Overview of this book

Table of Contents (15 chapters)
OpenCV 3.0 Computer Vision with Java
Credits
About the Author
Acknowledgment
About the Reviewers
www.PacktPub.com
Preface
Index

Capturing a video from a camera


The process of capturing frames from a webcam is very complex and it involves hardware details as well as heavy decoding or decompression algorithms. Fortunately, OpenCV has wrapped it all in a simple, yet powerful class called VideoCapture. This class not only grabs an image from a webcam, but also reads video files. In case more advanced access to a camera is required, you may want to use its specialized drivers.

You can think of a video stream as a series of pictures and you can retrieve each image in Mat and process it as you like. In order to use the VideoCapture class to capture a webcam stream, you need to instantiate it using the VideoCapture(int device) constructor. Note that the constructor parameter refers to the camera index in case you have several cameras. So, if you have one built-in camera and one USB camera and you create a videocapture object, such as new VideoCapture(1), then this object will refer to your built-in camera, while new VideoCapture...