根据预测框在框内找固定的点
import cv2
def draw_fixed_point(image, detection_box):
# 计算目标检测框的中心点坐标
x_center = (detection_box[0] + detection_box[2]) // 2
y_center = (detection_box[1] + detection_box[3]) // 2
# 计算固定距离框的边界坐标
d = 2 # 固定距离框的距离
fixed_box = [
x_center - d,
y_center - d,
x_center + d,
y_center + d
]
# 绘制固定距离框的点
cv2.circle(image, (x_center, y_center), 2, (0, 0, 255), -1) # 绘制中心点
cv2.rectangle(image, (fixed_box[0], fixed_box[1]), (fixed_box[2], fixed_box[3]), (0, 0, 255), 2) # 绘制固定距离框
return image
# 示例用法
image_path = 'image.jpg' # 图像的文件路径
detection_box = [512, 512, 512, 512] # 目标检测框的坐标 [x1, y1, x2, y2]
# 读取图像
image = cv2.imread(image_path)
# 在图像上绘制固定距离框的点
image_with_fixed_point = draw_fixed_point(image, detection_box)
# 显示结果图像
cv2.imshow('Image with Fixed Point', image_with_fixed_point)
cv2.waitKey(0)
cv2.destroyAllWindows()