
绘制矩形内九个点的圆圈
给定一个矩形,由其左上角、右下角坐标确定:
- 左上角坐标:left = 530,top = 836
- 右下角坐标:right = 685,bottom = 885
任务是使用cv2.circle函数在矩形内绘制九个圆圈,分别对应以下位置:
- 左上
- 上中
- 右上
- 左中
- 中心
- 右中
- 左下
- 下中
- 右下
python代码:
import cv2
import numpy as np
# 创建一个白色画布
img = np.ones((1000, 1000), np.uint8) * 255
# 绘制矩形
cv2.rectangle(img, (left, top), (right, bottom), 0)
# 绘制圆圈
for y in range(top * 2, bottom * 2 + 1, bottom - top):
for x in range(left * 2, right * 2 + 1, right - left):
cv2.circle(img, (x, y), 8, 0, cv2.FILLED, cv2.LINE_AA, 1)
# 显示图像
cv2.imshow('img', img)
cv2.waitKey()结果:
执行代码后,将在屏幕上显示绘制了九个圆圈的矩形图像。










