标签:flat rand imwrite byte numpy utf8 res image write
1 # coding:utf8
2 import cv2
3 import numpy
4 import os
5
6
7 """
8 随机字节的bytearray转为灰度图像和BGR图像
9 """
10 randomByteArray = bytearray(os.urandom(120000))
11 flatNumpyArray = numpy.array(randomByteArray)
12 # 转换成400*300的灰度图像
13 grayImage = flatNumpyArray.reshape(400, 300)
14 cv2.imwrite("randomGray.png", grayImage)
15
16 """
17 随机字节的bytearray转为400*100的彩色图像
18 """
19 bgrImage = flatNumpyArray.reshape(400, 100, 3)
20 cv2.imwrite("randomColor.png", bgrImage)
标签:flat rand imwrite byte numpy utf8 res image write
原文地址:https://www.cnblogs.com/Lin-Yi/p/9391474.html