Skip to Content
OpenCV with Python By Example
book

OpenCV with Python By Example

by Prateek Joshi
September 2015
Beginner to intermediate
296 pages
5h 57m
English
Packt Publishing
Content preview from OpenCV with Python By Example

Reading, displaying, and saving images

Let's see how we can load an image in OpenCV-Python. Create a file named first_program.py and open it in your favorite code editor. Create a folder named images in the current folder and make sure that you have an image named input.jpg in that folder.

Once you do that, add the following lines to that Python file:

import cv2
img = cv2.imread('./images/input.jpg')
cv2.imshow('Input image', img)
cv2.waitKey()

If you run the preceding program, you will see an image being displayed in a new window.

What just happened?

Let's understand the previous piece of code, line by line. In the first line, we are importing the OpenCV library. We need this for all the functions we will be using in the code. In the second line, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

OpenCV 4 with Python Blueprints - Second Edition

OpenCV 4 with Python Blueprints - Second Edition

Dr. Menua Gevorgyan, Michael Beyeler (USD), Arsen Mamikonyan, Michael Beyeler
OpenCV By Example

OpenCV By Example

Prateek Joshi, David Millán Escrivá, Vinícius G. Mendonça
OpenCV 3 Computer Vision with Python Cookbook

OpenCV 3 Computer Vision with Python Cookbook

Aleksei Spizhevoi, Aleksandr Rybnikov

Publisher Resources

ISBN: 9781785283932Supplemental Content