from glob import glob
import cv2
import os.path as osp
label_path_list = glob("./coco/*.txt")
img_path_list = []
for label_path in label_path_list:
tmp = osp.basename(label_path).split(".")[0]
a = f"coco/{tmp}.*"
img_path_list.append(glob(a)[0])
for i_p, l_p in zip(img_path_list, label_path_list):
print(i_p, l_p)
original = cv2.imread(i_p)
with open(l_p, "r") as f:
src_labels = f.readlines()
for src_label in src_labels:
class_id, x_c, y_c, x_w, y_w = src_label.replace("\n", "").split(" ")
class_id = int(class_id)
x_c, y_c, x_w, y_w = int(float(x_c) * 640), int(float(y_c) * 640), int(float(x_w) * 640), int(float(y_w) * 640)
lu = (x_c - (x_w // 2), y_c - (y_w // 2))
rd = (x_c + (x_w // 2), y_c + (y_w // 2))
cv2.rectangle(original, lu, rd, (50, 200, 50), 5)
cv2.imshow("tmp", original)
cv2.waitKey()