git: https://github.com/linyi0604/Computer-Vision 

 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)

 

相关文章:

  • 2021-06-15
  • 2022-01-11
  • 2022-01-19
  • 2022-02-08
  • 2021-07-11
  • 2022-02-25
  • 2021-12-24
猜你喜欢
  • 2021-12-23
  • 2022-02-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2021-06-17
  • 2022-12-23
相关资源
相似解决方案