In this article, we’ll try to open an image by using OpenCV (Open Source Computer Vision). To use the OpenCV library in python, we need to install these libraries as a prerequisite:
To install these libraries, we need to run these pip commands in cmd:
import cv2
img = cv2.imread('machinelearning.png',cv2.IMREAD_GRAYSCALE)
cv2.imshow('Machine Learning',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Note: Instead of writng cv2.IMREAD_GRAYSCALE, write 0 to read image as GrayScale image
import cv2
img = cv2.imread('machinelearning.png',0)
cv2.imshow('Machine Learning',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
img = cv2.imread('machinelearning.png',cv2.IMREAD_COLOR)
cv2.imshow('Machine Learning',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Note: Instead of writng cv2.IMREAD_COLOR, write 1 to read image as color image
import cv2
img = cv2.imread('machinelearning.png',1)
cv2.imshow('Machine Learning',img)
cv2.waitKey(0)
cv2.destroyAllWindows()