在python里导入OpenCV包
import numpy as np
import cv2
读取并显示图像(bmp,jpg,png,tiff)
img=cv2.imread()
创建一个窗口
cv2.namedWindow("Image")
在窗口中显示图像
cv2.imshow("Image",img)
在窗口显示时
cv.2waitKey(0)
关闭所有窗口
cv2.destroyAllWindows()
复制图片,保存图片格式等相关问题
import cv2
import numpy as np
img=cv2.imread("/Users/guiyanan/Desktop/xjtlu.jpg")
#get new image
emptyImage = np.zeros(img.shape, np.uint8)
#copy get a new image
emptyImage2 = img.copy()
#change the color of image
emptyImage3=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#emptyImage3[...]=0 transmit black blank image
cv2.imshow("EmptyImage", emptyImage)
cv2.imshow("Image", img)
cv2.imshow("EmptyImage2", emptyImage2)
cv2.imshow("EmptyImage3", emptyImage3)
# for jpeg third is quality of image for png zip degree
cv2.imwrite("/Users/guiyanan/Desktop/xjtlu1.jpg", img,[int(cv2.IMWRITE_JPEG_QUALITY),5])
cv2.imwrite("/Users/guiyanan/Desktop/xjtlu2.jpg", img, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
cv2.imwrite("/Users/guiyanan/Desktop/xjtlu3.png", img, [int(cv2.IMWRITE_PNG_COMPRESSION), 0])
cv2.imwrite("/Users/guiyanan/Desktop/xjtlu4.png", img, [int(cv2.IMWRITE_PNG_COMPRESSION), 9])
cv2.waitKey (0)
cv2.destroyAllWindows()
原文:http://www.cnblogs.com/gzoof/p/6699445.html