O'Reilly logo

Machine Learning for OpenCV by Michael Beyeler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Visualizing the true-color palette

Let's have a look at a particular image:

In [1]: import cv2...     import numpy as np...     lena = cv2.imread('data/lena.jpg', cv2.IMREAD_COLOR)

By now, we know how to start matplotlib in our sleep:

In [2]: import matplotlib.pyplot as plt...     %matplotlib inline...     plt.style.use('ggplot')

However, this time we want to disable the grid lines that the ggplot option typically displays over images:

In [3]: plt.rc('axes', **{'grid': False})

Then we can visualize Lena with the following command (don't forget to switch the BGR ordering of the color channels to RGB):

In [4]: plt.imshow(cv2.cvtColor(lena, cv2.COLOR_BGR2RGB))

This will produce the following output:

A picture of Lena (http://sipi.usc.edu/database/database.php?volume=misc&image=12). ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required