1. Home
  2. Docs
  3. Computer Vision
  4. Introduction to OpenCV
  5. Opening Image Files with ...
  6. Reading Image in OpenCV

Reading Image in OpenCV

cv2 is the namespace for opencv library

import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline

img = cv2.imread("parrot.jpg")

cv2.imread // automatically reads the image as numpy array

When the path specified in the imread( ) is wrong, then it does not show the error rather it shows the type as None

  • imread() – to load an image from the specified file
  • The input is the path of the image. The result is a numpy array with intensity values as 8 bits

To get the size of the image

img.shape

To print the pixel value of the image

img

To display the image

plt.imshow(img)

While trying to show the image, the color appears off

This is because the order of each channel is different in OpenCV

The image is shown as bluish tint. Why?

  • Because OpenCV and matplotlib expects different orders of red, green and blue channels
  • Matplotlib reads the images as Red, Green, Blue
  • OpenCV reads the images as Blue, Gree, Red

PIL vs OpenCV

Loading

Views: 1

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments