O'Reilly logo

Raspberry Pi Computer Vision Programming by Ashwin Pajankar

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

Working with images

Let's get started with the basics of OpenCV's Python API. All the scripts we will write and run will be done using the OpenCV library, which must be imported with the line import cv2. We will import a few more libraries as needed in the next sections and chapters.

The cv2.imread() method is used to import an image. It takes two arguments. The first argument is the image filename. The image should either be in the same directory where the Python script is, or the absolute path should be provided to cv2.imread(). It reads images and saves it as a NumPy array.

The second argument is a flag which specifies the mode the image should be read in. The flag can have following values:

  • cv2.IMREAD_COLOR: This loads a color image. This is ...

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