first commit

This commit is contained in:
hatcher committed 2026-07-17 18:55:31 +08:00
1 parent ae53e9eac5
commit 91cbd01126
514 files changed
+55625 -2203

No files matched your search

+57 -3
View File
@@ -7,8 +7,9 @@ output:xml文件
'''
import numpy as np
from lxml import etree
from common import global_para as gp
import xmltodict
import json,time
class GEN_Annotations:
def __init__(self, filename):
self.root = etree.Element("annotation")
@@ -59,6 +60,7 @@ class GEN_Annotations:
ymaxn.text = str(ymax)
scoren = etree.SubElement(bndbox, "score")
scoren.text = str(score)
def add_pic_attr_bird(self, label, xmin, ymin, xmax, ymax):
object = etree.SubElement(self.root, "object")
namen = etree.SubElement(object, "name")
@@ -81,10 +83,61 @@ class GEN_Annotations:
for j in i:
density.attrib["att{}".format(num)] = j
num+=1
class GEN_Annotations_scan(GEN_Annotations):
def __init__(self, record_time,serial_number):
super(GEN_Annotations,self).__init__()
self.root = etree.Element("annotation")
child1 = etree.SubElement(self.root, "record_time")
child1.text = record_time
child2 = etree.SubElement(self.root, "serial_number")
child2.text = serial_number
def add_pic_attr_scan(self, label, xmin, ymin, xmax, ymax):
object = etree.SubElement(self.root, "data")
namen = etree.SubElement(object, "species_name")
namen.text = str(label)
bndbox = etree.SubElement(object, "bndbox")
pos_x = etree.SubElement(bndbox, "site_x")
pos_x.text = str("1")
pos_y = etree.SubElement(bndbox, "site_y")
pos_y.text = str("1")
xminn = etree.SubElement(bndbox, "xmin")
xminn.text = str(xmin)
yminn = etree.SubElement(bndbox, "ymin")
yminn.text = str(ymin)
xmaxn = etree.SubElement(bndbox, "xmax")
xmaxn.text = str(xmax)
ymaxn = etree.SubElement(bndbox, "ymax")
ymaxn.text = str(ymax)
scoren = etree.SubElement(object, "habitat")
scoren.text = str("")
def make_xml_scan(record_time,serial_number, boxes,labels,savename):
anno = GEN_Annotations_scan(record_time,serial_number)
#anno.set_size(size_y, size_x, 3)
for i in range(len(boxes)):
xmin = int(boxes[i][0])
ymin = int(boxes[i][1])
xmax = int(boxes[i][2])
ymax = int(boxes[i][3])
# size_x1 = size_x[i]
# size_y1 = size_y[i]
anno.add_pic_attr_scan(str(labels[i]), xmin, ymin, xmax, ymax)
anno.savefile("./temp.xml")
with open("./temp.xml", 'r', encoding='UTF-8')as json_file:
xml_data = json_file.read()
json_file.close()
jsonstr = xmltodict.parse(xml_data, encoding='UTF-8')
json_conversion = json.dumps(jsonstr["annotation"]) # 将python对象编码成Json字符串
with open(savename, 'w') as json_file:
json_file.write(json_conversion) # 写入文件
json_file.close()
return jsonstr["annotation"]
def make_xml(filename,size_x,size_y,boxes,labels,scores,savename):
anno = GEN_Annotations(filename)
@@ -95,7 +148,8 @@ def make_xml(filename,size_x,size_y,boxes,labels,scores,savename):
xmax = int(boxes[i][2])
ymax = int(boxes[i][3])
score = int(scores[i]*1000)
anno.add_pic_attr("bird", xmin, ymin, xmax, ymax,score)
anno.add_pic_attr(gp.BHG_chineseName[int(labels[i])], xmin, ymin, xmax, ymax,score)
print("细粒度识别结果为:",gp.BHG_chineseName[int(labels[i])])
anno.savefile(savename)
def make_xml_iccv(filename,size_x,size_y,boxes,savename):
anno = GEN_Annotations(filename)