1、cv2.imread() to read an image
cv2.IMREAD_COLOR: load a color image
cv2.IMREAD_GRAYSCALE: loads image in grayscale mode
cv2.IMREAD_UNCHANGED: Loads image as such including alpha channel
下面是读一幅图像和显示一幅图像,cv.waitKey() is a keyboard function. Its argument is the time in milliseconds, 里面的参数也可能是一个具体的字母。 cv.destroyAllWindows() simply destroys all the windows.
cv.destroyWindow() where you pass the exact window name as the argument.
#encoding=utf-8import cv2 as cvimport numpy as np#Load an color image in grayscaleimg=cv.imread('C:\Users\Administrator\Desktop\lena.jpg',0)#imshow an imagecv.imshow('img',img)cv.waitKey(0)#这里要注意字母大小写的问题cv.destoryAllWindows()
2、下面是定义一个窗口的名字,并在窗口中显示图像,其中cv.WINDOW_AUTOSIZE()默认显示图像的大小,cv.WINDOW_NORMAL()可以根据图像的大小自动调节窗口的大小。
import cv2 as cvimport numpy as npimg=cv.imread('C:\Users\Administrator\Desktop\lena.jpg',0)cv.namedWindow('image',cv.WINDOW_NORMAL)cv.imshow('image',img)cv.waitKey(0)cv.destroyAllWindows()
3、Use the function cv.imwrite() to save an image. First argument is the file name,secong argument is the image you want to save.s
cv.imwrite('C:\Users\Administrator\Desktop\lena.jpg',img)