目标检测后处理-检测框内找点

根据预测框在框内找固定的点

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()

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

VisionX Lab

你的鼓励将是我更新的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值