赞
踩
提示:文章用于学习记录
将下载的包解压到一个路径,打开该文件夹并点击上方搜索栏,输入 cmd
按下回车,进入该目录的 cmd 终端输入 python,再输入 conda 检测环境变量
输入以下命令,会自动完成安装
conda install pyqt=5
由于已安装,故出现 All requested packages already installed. 表明已经安装好了。
pip install lxml -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install PyQt5 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install PyQt5_tools -i https://pypi.tuna.tsinghua.edu.cn/simple
4. 再输入 Pyrcc5 -o resources.py resources.qrc,并运行 labelImg.py,报错 ModuleNotFoundError: No module named ‘libs.resources‘
Pyrcc5 -o resources.py resources.qrc
python labelImg.py
5. 以上报错解决方案将 labelImg-master 中的 resources.py 复制到 lib 文件中,如下图:
6. 再终端输入命令 python labelImg.py 即可打开 labelImg,也可在目录双击 labelImg.py 打开.
import xml.etree.ElementTree as ET import os def convert(size, box): x_center = (box[0] + box[1]) / 2.0 y_center = (box[2] + box[3]) / 2.0 x = x_center / size[0] y = y_center / size[1] w = (box[1] - box[0]) / size[0] h = (box[3] - box[2]) / size[1] return (x, y, w, h) def convert_annotation(xml_files_path, save_txt_files_path, classes): xml_files = os.listdir(xml_files_path) print(xml_files) for xml_name in xml_files: print(xml_name) xml_file = os.path.join(xml_files_path, xml_name) out_txt_path = os.path.join(save_txt_files_path, xml_name.split('.')[0] + '.txt') out_txt_f = open(out_txt_path, 'w') tree = ET.parse(xml_file) root = tree.getroot() size = root.find('size') w = int(size.find('width').text) h = int(size.find('height').text) for obj in root.iter('object'): # difficult = obj.find('difficult').text if obj.find('difficult'): difficult = float(obj.find('difficult').text) else: difficult = 0 cls = obj.find('name').text if cls not in classes or int(difficult) == 1: continue cls_id = classes.index(cls) xmlbox = obj.find('bndbox') b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text)) # b=(xmin, xmax, ymin, ymax) print(w, h, b) bb = convert((w, h), b) out_txt_f.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n') if __name__ == "__main__": # 需要转换的类别,需要一一对应 classes1 = ['D00','D10','D20','D40'] # 2、voc格式的xml标签文件路径 xml_files1 = r'C:\Users\bistu\Desktop\RoadDamage\labels' # 3、转化为yolo格式的txt标签文件存储路径 save_txt_files1 = r'C:\Users\bistu\Desktop\batch\label' convert_annotation(xml_files1, save_txt_files1, classes1)
以上就是LabelImg 安装与使用、XML 数据格式转化为 TXT 以及 makesense 在线标注工具的使用。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。