首页 > 其他 > 详细

OpenCV01

时间:2017-04-14 12:47:34      阅读:195      评论:0      收藏:0      [点我收藏+]

在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()

OpenCV01

原文:http://www.cnblogs.com/gzoof/p/6699445.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!