open cv 创建一个300*300的白色画布,在画布上绘制箭靶并标注环数,圆环数横着标注,一共5圈,最里圈为红色实心圆
时间: 2024-05-22 14:16:05 浏览: 180
以下是Python代码:
```python
import cv2
import numpy as np
# 创建一个300*300的白色画布
canvas = np.ones((300,300,3), dtype=np.uint8) * 255
# 绘制箭靶
center = (150,150)
for i in range(5):
radius = (i+1) * 30
color = (0, 0, 255) if i == 4 else (0, 255, 0)
cv2.circle(canvas, center, radius, color, thickness=2)
# 标注圆环数
for i in range(5):
text = str(i+1)
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 0.5
color = (0, 0, 0)
thickness = 1
text_size, _ = cv2.getTextSize(text, font, font_scale, thickness)
text_org = (center[0]-text_size[0]//2, center[1]+(i+1)*30+text_size[1]//2)
cv2.putText(canvas, text, text_org, font, font_scale, color, thickness)
# 显示画布
cv2.imshow("Arrow Target", canvas)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
运行结果如下:
![arrow_target](https://user-images.githubusercontent.com/58980799/130315454-04d8b8e6-1a0b-41c9-a9a9-7b2b67e2a7f7.png)
阅读全文