yolov8直接调用zed相机实现三维测距(python)_yolov8检测物体的世界坐标高度

from time import sleep

import ogl_viewer.viewer as gl
import cv_viewer.tracking_viewer as cv_viewer

lock = Lock()
run_signal = False
exit_signal = False

def xywh2abcd(xywh, im_shape):
output = np.zeros((4, 2))

# Center / Width / Height -> BBox corners coordinates
x_min = (xywh[0] - 0.5\*xywh[2]) #\* im\_shape[1]
x_max = (xywh[0] + 0.5\*xywh[2]) #\* im\_shape[1]
y_min = (xywh[1] - 0.5\*xywh[3]) #\* im\_shape[0]
y_max = (xywh[1] + 0.5\*xywh[3]) #\* im\_shape[0]

# A ------ B
# | Object |
# D ------ C

output[0][0] = x_min
output[0][1] = y_min

output[1][0] = x_max
output[1][1] = y_min

output[2][0] = x_max
output[2][1] = y_max

output[3][0] = x_min
output[3][1] = y_max
return output

def detections_to_custom_box(detections, im0):
output = []
for i, det in enumerate(detections):
xywh = det.xywh[0]

    # Creating ingestable objects for the ZED SDK
    obj = sl.CustomBoxObjectData()
    obj.bounding_box_2d = xywh2abcd(xywh, im0.shape)
    obj.label = det.cls
    obj.probability = det.conf
    obj.is_grounded = False
    output.append(obj)
return output

def torch_thread(weights, img_size, conf_thres=0.2, iou_thres=0.45):
global image_net, exit_signal, run_signal, detections

print("Intializing Network...")

model = YOLO(weights)

while not exit_signal:
    if run_signal:
        lock.acquire()

        img = cv2.cvtColor(image_net, cv2.COLOR_BGRA2RGB)
        # https://docs.ultralytics.com/modes/predict/#video-suffixes
        det = model.predict(img, save=False, imgsz=img_size, conf=conf_thres, iou=iou_thres)[0].cpu().numpy().boxes

        # ZED CustomBox format (with inverse letterboxing tf applied)
        detections = detections_to_custom_box(det, image_net)
        lock.release()
        run_signal = False
    sleep(0.01)

def main():
global image_net, exit_signal, run_signal, detectio

  • 13
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值