import cv2 as cv2
img = cv2.imread('C:\\Users\\zzheng\\Pictures\\tiger.png')
cv2.imshow('sample image', img)
cv2.waitKey(0) # waits until a key is pressed
cv2.destroyAllWindows() # destroys the window showing image
cv2.imread(/complete/path/to/image,flag):
cv2.IMREAD_COLOR : Loads a color image. Any transparency of image will be neglected. It is the default flag.
cv2.IMREAD_GRAYSCALE : Loads image in grayscale mode
cv2.IMREAD_UNCHANGED : Loads image as such including alpha channelReturns numpy array, containing the pixel values. For colored images, each pixel is represented as an array containing Red, Green and Blue channels.
Note that the default flag is cv2.IMREAD_COLOR. Hence even if read a png image with transparency, the transparency channel is neglected.
网友评论