OpenCV is a popular library in the computer vision community, being actively used in industry and academy. Started in 1999 and popularized in the following decade, OpenCV is covered in books and tutorials, so this text will not provide another overview of the library. The interested reader that is not familiar to OpenCV is referred to those cited texts and the library’s official documentation.
Developed in efficient C/C++ code, OpenCV presents a stable Python interface since 2009. The functions’ prototypes in the Python API can differ from the C++ version, but the OpenCV documentation presents both versions for reference. IPython code completion capabilities can also help programmers used to the C++ API to quickly identify the proper Python prototypes.
Let's play with interactive frame grabbing from a video camera:
capture = cv2.VideoCapture(1)
val, image = capture.read()
<matplotlib.image.AxesImage at 0x7fa557d9f490>
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) imshow(image_rgb)
<matplotlib.image.AxesImage at 0x7fa54c352090>
In OpenCV operation under Python, NumPy arrays replace the OpenCV’s
Mat type as the data structure for images. NumPy arrays will be presented in the next section.