- Create randomPic.py file
-
import cv2 import numpy import os #产生随机数组 randomByteArray = bytearray(os.urandom(120000)) flatNumpyArray = numpy.array(randomByteArray) #数组转换为一个300*400的灰度图像 grayImage = flatNumpyArray.reshape(300,400) cv2.imwrite('RandomGray.png',grayImage) #数组转换为一个100*400的彩色图像 bgrImage = flatNumpyArray.reshape(100,400,3) cv2.imwrite('RandomColor.png',bgrImage)
- Running the script will generate two random images, the image names RandomGray.png and RandomColor.png.
Opencv random bytes to generate grayscale images and BGR images
Guess you like
Origin blog.csdn.net/sinat_38685910/article/details/94441605
Ranking