2 Star 3 Fork 2

SuperMapDesktop/deep-sort-yolov4

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
detectionBrokenRoad.py 3.06 KB
一键复制 编辑 原始数据 按行查看 历史
lier 提交于 2021-09-28 14:17 . 破损道路重现问题代码提交
import os
import sys
from yoloBrokedRoad import YOLOBrokenRoad
from PIL import Image
from xml.dom.minidom import *
def infer_img(yolo, img_dir,out_dir):
# sun
try:
os.path.exists(img_dir)
except:
print("dir error", img_dir)
imgType_list = {'jpg','bmp','png','jpeg','rgb','tif'}
img_list = os.listdir(img_dir)
for imgname in img_list:
if imgname.split(".")[-1] in imgType_list:
img_path = os.path.join(img_dir, imgname)
save_box_path = os.path.join(out_dir, imgname[:-4] + ".xml")
# fp = open(save_box_path, "w")
image = Image.open(img_path)
# try:
# image = Image.open(img_path)
# print(img_path,"has been opened!")
# except:
# print(img_path,"oped error!")
boxes, confidence, classes = yolo.detect_image(image) # sun
# box_str = ""
# for box in boxes:
# box_str = box_str + ",".join(str(i) for i in box) + " "
# print("img_path:", img_path, "boxes_str:", box_str)
box_str = ",".join([str(a) for a in boxes])
print("img_path:", img_path, "boxes_str:", box_str)
# fp.write(imgname[:-4] + str(box_str))
# fp.close()
doc=Document()
root=doc.createElement('bndboxs')
doc.appendChild(root)
for i in range(len(boxes)):
box=boxes[i]
object=doc.createElement('object')
bndbox=doc.createElement('bndbox')
xmin=doc.createElement('xmin')
xmin.appendChild(doc.createTextNode(str(box[0])))
ymin=doc.createElement('ymin')
ymin.appendChild(doc.createTextNode(str(box[1])))
xmax=doc.createElement('xmax')
xmax.appendChild(doc.createTextNode(str(box[2])))
ymax=doc.createElement('ymax')
ymax.appendChild(doc.createTextNode(str(box[3])))
bndbox.appendChild(xmin)
bndbox.appendChild(ymin)
bndbox.appendChild(xmax)
bndbox.appendChild(ymax)
score=doc.createElement('score')
score.appendChild(doc.createTextNode(str(confidence[i])))
object.appendChild(bndbox)
object.appendChild(score)
root.appendChild(object)
fp=open(save_box_path,'w',encoding='utf-8')
doc.writexml(fp,indent='',addindent='\t',newl='\n',encoding='utf-8')
fp.close()
sys.stdout.write("brokenRoadRunFinished\n")
yolo.close_session()
if __name__ == '__main__':
img_dir = r'E:\Work\2021\BrokenRoad\Track_A08\Test'
model_path = r'E:\Code\Python\SuperMapOpenProject\deep-sort-yolov4\model_data\brokenRoad\brokenroad.h5'
yolo_model = YOLOBrokenRoad(model_path)
infer_img(yolo_model, img_dir,r'E:\Work\2021\BrokenRoad\Track_A08\Test_boxes')
yolo_model1 = YOLOBrokenRoad(model_path)
infer_img(yolo_model1, img_dir,r'E:\Work\2021\BrokenRoad\Track_A08\Test_boxes1')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/SuperMapDesktop/deep-sort-yolov4.git
git@gitee.com:SuperMapDesktop/deep-sort-yolov4.git
SuperMapDesktop
deep-sort-yolov4
deep-sort-yolov4
master

搜索帮助