您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)VOC格式如何轉(zhuǎn)換CSV,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
import os import xml.dom.minidom path_img = "VOC2007/JPEGImages" path_xml = "VOC2007/Annotations" xml_list = [] for xml1 in os.listdir(path_xml): if xml1.endswith(".xml"): xml_list.append(xml1) csv_labels = open("csv_labels.csv", "w") for xml_file in xml_list: image_id, _ = os.path.splitext(xml_file) DomTree = xml.dom.minidom.parse(os.path.join(path_xml, xml_file)) annotation = DomTree.documentElement objectlist = annotation.getElementsByTagName('object') for objects in objectlist: namelist = objects.getElementsByTagName('name') objectname = namelist[0].childNodes[0].data bndbox = objects.getElementsByTagName("bndbox") for box in bndbox: x1_list = box.getElementsByTagName('xmin') x1 = int(x1_list[0].childNodes[0].data) y1_list = box.getElementsByTagName('ymin') y1 = int(y1_list[0].childNodes[0].data) x2_list = box.getElementsByTagName('xmax') x2 = int(x2_list[0].childNodes[0].data) y2_list = box.getElementsByTagName('ymax') y2 = int(y2_list[0].childNodes[0].data) line = str(image_id) + "," + str(x1) + "," + str(y1) \ + "," + str(x2) + "," + str(y2) + "," + objectname + "\n" print(line) csv_labels.write(line) csv_labels.close()
關(guān)于VOC格式如何轉(zhuǎn)換CSV就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。