环境
Anaconda+python3.5.2+opencv3
1.
先测试一下numpy的矩阵。
import numpy as np import cv2 img=np.zeros((3,3),dtype=np.uint8) print(img.shape) img=cv2.cvtColor(img,cv2.COLOR_GRAY2BGR) print(‘\n‘) print(img.shape) print(‘\n‘) print(img)
2.
import cv2 grayImage=cv2.imread(‘/home/cisco/Pictures/Webcam/ss.jpg‘,0) cv2.imwrite(‘ssgray.jpg‘,grayImage) AnyColor=cv2.imread(‘/home/cisco/Pictures/Webcam/ss.jpg‘,4) cv2.imwrite(‘ssAnyColor.jpg‘,AnyColor)
src
grayImage
AnyColor
3.
Random Array into PNG
import cv2 import numpy as np import os randomByteArray=bytearray(os.urandom(120000)) flatNumpyArray=np.array(randomByteArray) grayImage =flatNumpyArray.reshape(300,400) cv2.imwrite(‘RandomGray.png‘,grayImage) bgrImage=flatNumpyArray.reshape(100,400,3) cv2.imwrite(‘RandomColor.png‘,bgrImage)
Random Gray
Random Color
时间: 2024-10-29 07:14:26