码迷,mamicode.com
首页 > 其他好文 > 详细

opencv

时间:2016-06-07 19:27:19      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:

读入图片

cv2.imread()

第一个参数:图片名

第二个参数:

• 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 channel
Note: Instead of these three flags, you can simply pass integers 1, 0 or -1 respectively.

1   import numpy as np
2   import cv2
3   img = cv2.imread(test.jpg,0) #显示一张灰度图

 显示图片

cv2.imshow()

1 cv2.imshow(image,img)
2 cv2.waitKey(0)
3 cv2.destroyAllWindows()

写入图片

cv2.imwrite()

1 cv2.imwrite(‘test.png,img)

打开图片,处理并保存的整个流程

 1 import numpy as np
 2 import cv2
 3 img = cv2.imread(test.jpg,0)
 4 cv2.imshow(image,img)
 5 k = cv2.waitKey(0)
 6 if k == 27:# wait for ESC key to exit
 7     cv2.destroyAllWindows()
 8 elif k == ord(s): # wait for ‘s‘ key to save and exit
 9     cv2.imwrite(testgray.png,img)
10     cv2.destroyAllWindows()

 

opencv

标签:

原文地址:http://www.cnblogs.com/weixinforspurs/p/5568060.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!