How it works...

Matrices are presented with NumPy array classes. These arrays have methods to compute mean values and standard deviations. To normalize a matrix—that is, to get a zero-mean and unit-variance matrix—we need to subtract the mean value, which we can get by calling mean and dividing the matrix by its standard deviation. You can also use the cv2.meanStdDev function, which computes both mean and standard deviation simultaneously.

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.