【代码模板】可视化

Pillow

Document

  • data format - (H, W, C), RGB
  • data dtype - np.uint8
  • value range - (0, 255)
from PIL import Image

# Read images
img = Image.open("img.png").convert('RGB') # 读取RGB图像 
img = Image.open("img.png").convert('L') # 读取灰度图像(H, W) uint8 [0, 255]
image = Image.fromarray(numpy_array) # Read from numpy.ndarray

# Data translation
img_ndarray = np.array(img_Image) # PIL.Image转numpy.adarray

Opencv

  1. 获得视频的信息
fps = int(cap.get(cv2.CAP_PROP_FPS))
n_frames = int(cap.get(7))
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))  
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
  1. 绘制
# 文本
frame = cv2.putText(frame, 'str', (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), thickness=2)
# 矩形
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), thickness=2)
# 圆
cv2.circle(image, center=(256, 256), radius=2, color=(0, 255, 0), thickness=2)
  1. 键盘交互
k = cv2.waitKey()
if k == ord('q'):
	# do something

你可能感兴趣的:(SOP,opencv,计算机视觉,人工智能)