How to do it...

Use following steps:

  1. Import all necessary modules:
import cv2import numpy as np
  1. Load an image and print its shape and type:
image = cv2.imread('../data/Lena.png').astype(np.float32) / 255print('Shape:', image.shape)print('Data type:', image.dtype)
  1. Convert the image to grayscale:
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)print('Converted to grayscale')print('Shape:', gray.shape)print('Data type:', gray.dtype)cv2.imshow('gray', gray)cv2.waitKey()cv2.destroyAllWindows()
  1. Convert the image to HSV color space:
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)print('Converted to HSV')print('Shape:', hsv.shape)print('Data type:', hsv.dtype)cv2.imshow('hsv', hsv)cv2.waitKey()cv2.destroyAllWindows()
  1. Increase the brightness of ...

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.