
求矩形内九个点的坐标并用opencv画圆
给定一个矩形的left、top、right、bottom坐标,需要分别求出矩形内部九个点的坐标,分别为: левый上、上中、右上、左中、中心、右中、左下、下中、右下。
使用python和opencv,我们可以轻松求出这些点坐标并将其绘制为圆圈。以下代码展示了如何实现:
import cv2
import numpy as np
# 矩形坐标
left, top, right, bottom = 530, 836, 685, 885
# 创建一个白色画布
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()










