open cv 创建一个300*300的画布,在画布上绘制箭靶并标注环数,中间内圆红色,标靶数为蓝色,最远圆环数为6,最内为9
时间: 2024-05-25 21:19:14 浏览: 236
以下是Python代码实现:
```python
import cv2
import numpy as np
# 创建300*300画布
canvas = np.zeros((300, 300, 3), dtype="uint8")
# 箭靶中心坐标
center = (150, 150)
# 绘制箭靶
for i in range(9, 0, -1):
# 计算圆环半径
radius = i * 10
# 计算圆环颜色
color = (255 - (i-1)*25, 0, (i-1)*25)
# 绘制圆环
cv2.circle(canvas, center, radius, color, 2)
# 标注圆环号数
cv2.putText(canvas, str(i), (center[0] - 5, center[1] + (10-i)*20 + 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
# 绘制内圆
cv2.circle(canvas, center, 10, (0, 0, 255), -1)
# 标注靶心数
cv2.putText(canvas, "10", (center[0] - 5, center[1] + 5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
# 显示图像
cv2.imshow("Target", canvas)
cv2.waitKey(0)
```
运行结果如下:
![target](https://img-blog.csdnimg.cn/20210504110119845.png)
阅读全文