OpenCV Python Tutorial For Beginners – How to Read, Write, Show Images in OpenCV




In this post on OpenCV Python Tutorial For Beginners, I am going to show How to Read, Write, Show Images in OpenCV. we will se how to use cv2.imread(‘lena.jpg’, -1) to read and image, cv2.imshow(‘image’, img) to show an image in a window, cv2.waitKey(0) to wait for a key event, cv2.destroyAllWindows() to destroy all windows, cv2.imwrite(‘lena_copy.png’, img) to write images to file.

OpenCV github page- https://github.com/opencv/opencv

Install PyCharm ( Python IDE ) on Windows 10 + First Project
Read an image
cv2.imread() Second argument is a flag which specifies the way image should be read.
flag integer value description
cv2.IMREAD_COLOR 1 Loads a color image.
cv2.IMREAD_GRAYSCALE 0 Loads image in grayscale mode
cv2.IMREAD_UNCHANGED -1 Loads image as such including alpha channel

Image used in this example
lena


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com