码农知识堂 - 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])

  • 相关阅读:
    Java中HashMap之replace()方法具有什么功能呢?
    【无标题】
    刷题笔记(js)
    【华为OD机试真题 python】矩阵扩散 【2022 Q4 | 200分】
    数据隐私、AI 交互和知识管理:DB-GPT 的综合解决方案 | 开源日报 0905
    38. 干货系列从零用Rust编写负载均衡及代理,负载均衡中ip通行与禁止
    Go的简单入门:开始使用泛型
    CVPR2019 | 29篇目标检测相关论文汇总(含2D/3D/显著性目标检测等)
    【图像压缩】基于余弦变换及霍夫曼编码实现jpeg压缩和解压附matlab代码
    Vue---网络
  • 原文地址:https://blog.csdn.net/m0_72572822/article/details/132819895
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号