September 2015
Beginner to intermediate
296 pages
5h 57m
English
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.
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, ...