Book Image

Python Game Programming By Example

Book Image

Python Game Programming By Example

Overview of this book

Table of Contents (14 chapters)
Python Game Programming By Example
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Configuring cameras


OpenCV provides a class, called cv2.VideoCapture, that represents a stream of images from either a video file or a camera. This class has methods such as read(image) for exposing the stream's next image as a NumPy array. It also has the get(propId) and set(propId, value) methods for accessing properties such as the width and height (in pixels), color format, and frame rate. The valid properties and values may depend on the system's video codecs or camera drivers.

Across cameras, the default property values may differ dramatically. For example, one camera might default to an image size of 640 x 480, while another may default to 1920 x 1080. For greater predictability, we should try to set crucial parameters rather than rely on the defaults. Let's create a module called ResizeUtils containing a utility function to configure the image size.

The ResizeUtils module begins by importing the CVBackwardCompat instance of cv2, which may contain aliases (depending on the OpenCV version...