Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python Game Programming By Example

You're reading from   Python Game Programming By Example A pragmatic guide for developing your own games with Python

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781785281532
Length 230 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Supporting multiple versions of OpenCV


OpenCV 2.x and OpenCV 3.x both use the name cv2 for their top-level Python module. However, inside this module, some classes, functions, and constants have been renamed in OpenCV 3.x. Moreover, some functionality is entirely new in OpenCV 3.x, but our project relies only on functionality that is present in both major versions.

To bridge a few of the naming differences between versions 2.x and 3.x, we create a module, CVBackwardCompat. It begins by importing cv2:

import cv2

OpenCV's version string is stored in cv2.__version__. For example, its value may be 2.4.11 or 3.0.0. We can use the following line of code to get the major version number as an integer, such as 2 or 3:

CV_MAJOR_VERSION = int(cv2.__version__.split('.')[0])

For OpenCV 2.x (or earlier), we will inject new names into the imported cv2 module so that all the necessary OpenCV 3.x names will be present. Specifically, we need to create aliases for several constants that have new names in OpenCV...

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 €18.99/month. Cancel anytime