Understanding Read an Image to Numpy Array with Python cv2.imread()

We can use python opencv to read an image to numpy array. In this tutorial, we will show detailed information for you.

Understanding Read an Image to Numpy Array with Python cv2.imread()

1.Import library

import cv2

2.Read an image using cv2.imread()

im = cv2.imread('test.jpg')

3.We will show some information on im object

print(type(im))
# <class 'numpy.ndarray'>

print(im.shape)
# (225, 400, 3)

print(im.dtype)
# uint8

We should notice:

  • The shape of im is: row (height) x column (width) x color (3)
  • The color order is BGR instead of RGB

If you want to create a new image using opencv, you can read:

Save an Image in Python OpenCV