How it works...

As you know, matrices and images in the OpenCV Python package are presented with NumPy arrays. For example, cv2.imread in the previous code gives a colorful image, which is a three-dimensional array, where all three dimensions correspond to height, width, and channels, respectively. It can be imagined as a two-dimensional matrix with height by width elements, and each element stores three values for each red, green, and blue channel. This order of dimensions can be encoded as the letters height, width, and channels (HWC), and data along the channels dimension is stored in the order blue, green, red.

Tensors are multidimensional matrices. Many Deep Learning models accept four-dimensional floating point tensors three for height, ...

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.