Skip to content

Commit ee20456

Browse files
authored
Add files via upload
1 parent b05d16a commit ee20456

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

visual.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# 可视化TXT文件中的boxes到图片上
2+
import json
3+
import shutil
4+
import cv2
5+
6+
def select(txt_path, outpath, image_path):
7+
with open(txt_path, 'r') as file:
8+
lines = file.readlines()
9+
for line in lines:
10+
line = line.split()
11+
img_id = line[0]
12+
im_path = image_path + "/" + img_id
13+
img = cv2.imread(im_path)
14+
15+
ann = line[1]
16+
ann = ann.split(',')
17+
x, y, w, h = float(ann[0]), float(ann[1]), float(ann[2]), float(ann[3])
18+
x2, y2 = x + w, y - h
19+
# object_name = annos[j][""]
20+
# 将bbox转换为int,会有一点误差
21+
img = cv2.rectangle(img, (int(x), int(y)), (int(x2), int(y2)), (255, 0, 0), thickness=2)
22+
img_name = outpath + "/" + img_id
23+
cv2.imwrite(img_name, img)
24+
# continue
25+
print(img_id)
26+
27+
if __name__ == "__main__":
28+
txt_path = "/root/result.txt"
29+
out_path = "/root/visual_image"
30+
image_path = "/root/autodl-tmp/data/visdrone/VisDrone2019-DET-val/images"
31+
select(txt_path, out_path, image_path)

0 commit comments

Comments
 (0)