# !/usr/bin/env python
# -*-coding:utf-8 -*-
# File : test.py
# Time :2023/2/6 19:50
# Author :QQ736592720
import cv2
def yolo_cv_show(src,record="record.txt"):
image = cv2.imread(src)
h, w = image.shape[:2]
print(w, h)
with open("record.txt", "r") as f:
data = f.read() # 0 0.820717 0.5 0.239044 0.276382 0.810547 #带了conf
print(data)
ls = data.strip().split(" ")
x_, y_, w_, h_ = [float(i) for i in ls[-5:-1]] # 0.820717 0.5 0.239044 0.276382
x1 = w * x_ - 0.5 * w * w_
x2 = w * x_ + 0.5 * w * w_
y1 = h * y_ - 0.5 * h * h_
y2 = h * y_ + 0.5 * h * h_
# 画图验证,注意画图坐标要转换成int格式
cv2.rectangle(image, (int(x1), int(y1)), (int(x2), int(y2)), (255, 0, 0))
cv2.imshow('yolo', image)
cv2.waitKey(0)
if __name__ == '__main__':
src = r"D:\projects\pycharm_projects\yolo_v8\ultralytics-main\datasets\VOCdevkit\images\test\1672304514641.jpg"
yolo_cv_show(src)
yolo模型预测结果可视化函数封装
最新推荐文章于 2024-05-08 16:50:50 发布