码迷,mamicode.com
首页 > 编程语言 > 详细

opencv(1)数组转化为图像

时间:2015-01-25 01:23:40      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

数组转化为图像Converting between an image and raw bytes

import cv2
import numpy
import os

# Make an array of 120,000 random bytes.
randomByteArray = bytearray(os.urandom(120000))
flatNumpyArray = numpy.array(randomByteArray)

# Convert the array to make a 400x300 grayscale image.
grayImage = flatNumpyArray.reshape(300, 400)
cv2.imwrite(‘RandomGray.png‘, grayImage)

# Convert the array to make a 400x100 color image.
bgrImage = flatNumpyArray.reshape(100, 400, 3)
cv2.imwrite(‘RandomColor.png‘, bgrImage)

 运行脚本后会在脚本的路径中找到两个随机值构成的图像 RandomGray.png and RandomColor.png 

opencv(1)数组转化为图像

标签:

原文地址:http://www.cnblogs.com/nwpuxuezha/p/4246921.html

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