self_example/TensorFlow_eaxmple/OpenCV_try/基本的图片读取.py

21 lines
892 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import numpy as np
import cv2
'''生成一个每个具体数值均为0的一个[300,300]的矩阵'''
'''从图片的角度生成一个每个像素点均为黑色的一个300*3000的图片'''
img = np.mat(np.zeros((3, 3), dtype=np.uint8))
img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
print(img.shape)
print(img)
img[:, :, 0] = np.mat([[255, 0, 0], [255, 255, 0], [255, 128, 0]])
img[:, :, 1] = np.mat([[0, 255, 0], [255, 0, 255], [255, 128, 0]])
img[:, :, 2] = np.mat([[0, 0, 255], [0, 255, 255], [255, 128, 0]])
print(img)
'''这里是cv2输出图片的固定写法将刚才生成的一个矩阵以图片的形式在使用者计算机输出端上显示出来'''
cv2.imshow("test",img)
'''之后waitKey方法要求输出的图像暂时等待可以通过手动操作的形式取消图片显示若去掉则显示之后迅速消失'''
cv2.waitKey(0)
# (255,0,0),(0,255,0),(0,0,255)