python下使用OpenCV实现计算机视觉读书笔记2图像与字节的变换

Posted llguanli

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python下使用OpenCV实现计算机视觉读书笔记2图像与字节的变换相关的知识,希望对你有一定的参考价值。




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)

技术分享图片

技术分享图片

以上是关于python下使用OpenCV实现计算机视觉读书笔记2图像与字节的变换的主要内容,如果未能解决你的问题,请参考以下文章