赞
踩
目录
- import cv2
-
- # 读取图像
- img = cv2.imread('image.jpg')
-
- # 写中文
- cv2.putText(img, '中文', (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2, cv2.LINE_AA)
-
- # 显示图像
- cv2.imshow('image', img)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
-
- import cv2
- import numpy as np
- import matplotlib.pyplot as plt
-
- # 数据
- x_values = [1, 2, 3, 4, 5,6,7,8,9]
- y_values = [10, 12, 5, 8, 15,20,30,25,0]
-
- # 创建一个黑色背景的图像
- height, width = 300, 400 # 图像的高度和宽度
- background = np.zeros((height, width, 3), dtype=np.uint8) # 黑色背景
-
- # 将数据映射到图像坐标
- x_values_scaled = np.array(x_values) * (width - 1) // max(x_values)
- y_values_scaled = height - 1 - np.array(y_values) * (height - 1) // max(y_values)
-
- # 创建一个白色图线
- line_color = (255, 255, 255)
- thickness = 2
- for i in range(len(x_values) - 1):
- cv2.line(background, (x_values_scaled[i], y_values_scaled[i]),
- (x_values_scaled[i + 1], y_values_scaled[i + 1]), line_color, thickness,cv2.LINE_AA)
-
- # 保存图像
- cv2.imwrite('line_chart.png', background)

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。