绘制矩形内九个点的圆圈
给定一个矩形,由其左上角、右下角坐标确定:
左上角坐标:left = 530,top = 836右下角坐标:right = 685,bottom = 885
任务是使用cv2.circle函数在矩形内绘制九个圆圈,分别对应以下位置:
左上上中右上左中中心右中左下下中右下
python代码:
import cv2import 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()
结果:
执行代码后,将在屏幕上显示绘制了九个圆圈的矩形图像。
以上就是如何在矩形内绘制九个圆圈?的详细内容,更多请关注范的资源库其它相关文章!
转载请注明:范的资源库 » 如何在矩形内绘制九个圆圈?