码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • labelImg


    Look it in its website:

    GitHub - HumanSignal/labelImg: LabelImg is now part of the Label Studio community. The popular image annotation tool created by Tzutalin is no longer actively being developed, but you can check out Label Studio, the open source data labeling tool for images, text, hypertext, audio, video and time-series data.

    We can find the mothed of installing labelImg:

    So we could just input the command in cmd:

    pip install labelImg -i https://pypi.douban.com/simple

    Wait it for a while.

    Then we get the result.

    We could find it download PyQt5 automatically.

    Input labelImg in cmd, and we could see it:

    Then it saves a xml file in this floder:

    Let's see the xml :

    1. <annotation>
    2. <folder>labelimgfolder>
    3. <filename>bus.jpgfilename>
    4. <path>C:\Users\misty\Desktop\labelimg\bus.jpgpath>
    5. <source>
    6. <database>Unknowndatabase>
    7. source>
    8. <size>
    9. <width>810width>
    10. <height>1080height>
    11. <depth>3depth>
    12. size>
    13. <segmented>0segmented>
    14. <object>
    15. <name>personname>
    16. <pose>Unspecifiedpose>
    17. <truncated>0truncated>
    18. <difficult>0difficult>
    19. <bndbox>
    20. <xmin>41xmin>
    21. <ymin>395ymin>
    22. <xmax>259xmax>
    23. <ymax>910ymax>
    24. bndbox>
    25. object>
    26. <object>
    27. <name>shoename>
    28. <pose>Unspecifiedpose>
    29. <truncated>0truncated>
    30. <difficult>0difficult>
    31. <bndbox>
    32. <xmin>154xmin>
    33. <ymin>845ymin>
    34. <xmax>255xmax>
    35. <ymax>907ymax>
    36. bndbox>
    37. object>
    38. annotation>

    Python's xml module parses xml files.


    The information we need is the image width width, image height height, the coordinates xmin and ymin in the upper left corner of the detection box, and the coordinates xmax and ymax in the lower right corner of the detection box. We can run voc_label.py to generate YOLOv5 label file in labels folder. The data in each row of the label file are class, x,y, w,h, class is the category of the object, x and y are the center coordinates of the detection box, and w and h are the width and height of the detection box.

    voc_label.py code:

    1. import xml.etree.ElementTree as ET
    2. import os
    3. from os import getcwd
    4. from tqdm import tqdm
    5. classes = ["helmet", "person"]
    6. def convert(size, box):
    7. dw = 1. / size[0]
    8. dh = 1. / size[1]
    9. x = (box[0] + box[1]) / 2.0
    10. y = (box[2] + box[3]) / 2.0
    11. w = box[1] - box[0]
    12. h = box[3] - box[2]
    13. x = x * dw
    14. w = w * dw
    15. y = y * dh
    16. h = h * dh
    17. return (x, y, w, h)
    18. def convert_annotation(image_id):
    19. in_file = './xml/%s.xml' % (image_id)
    20. out_file = open('./labels/%s.txt' % (image_id), 'w')
    21. tree = ET.parse(in_file)
    22. root = tree.getroot()
    23. size = root.find('size')
    24. w = int(size.find('width').text)
    25. h = int(size.find('height').text)
    26. for obj in root.iter('object'):
    27. difficult = obj.find('Difficult').text
    28. cls = obj.find('name').text
    29. if cls not in classes or int(difficult) == 1:
    30. continue
    31. cls_id = classes.index(cls)
    32. xmlbox = obj.find('bndbox')
    33. b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text),
    34. float(xmlbox.find('ymax').text))
    35. bb = convert((w, h), b)
    36. out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
    37. if __name__ == "__main__":
    38. wd = getcwd()
    39. print(wd)
    40. if not os.path.exists('./labels/'):
    41. os.makedirs('./labels/')
    42. image_ids = os.listdir('./datasets')
    43. for image_id in tqdm(image_ids):
    44. convert_annotation(image_id.split('.')[0])

  • 相关阅读:
    React报错之Parameter 'event' implicitly has an 'any' type
    Linux 下 JDK 安装(tar.gz版) - jdk8
    C语言趣味代码(三)
    C Primer Plus(6) 中文版 第2章 C语言概述 2.3 简单程序的结构
    Kingbase+sqlsugar 携手助力医疗国产化替换 【人大金仓 .NET ORM】
    拼多多Temu正式卷到巴西,买家和卖家又多了一个选择!
    【关系抽取】基于Bert的信息抽取模型CasRel
    C# 11新特性之原始字符串
    MeiliSearch-轻量级且美丽的搜索引擎
    网鼎杯预赛2022密码
  • 原文地址:https://blog.csdn.net/m0_72572822/article/details/132819895
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号