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:

labelImg_第1张图片

So we could just input the command in cmd:

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

Wait it for a while.

labelImg_第2张图片

Then we get the result.

We could find it download PyQt5 automatically.

Input labelImg in cmd, and we could see it:

labelImg_第3张图片

Then it saves a xml file in this floder:

Let's see the xml :


    labelimg
    bus.jpg
    C:\Users\misty\Desktop\labelimg\bus.jpg
    
        Unknown
    
    
        810
        1080
        3
    
    0
    
        person
        Unspecified
        0
        0
        
        41
        395
        259
        910
        
    
    
        shoe
        Unspecified
        0
        0
        
            154
            845
            255
            907
        
    

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:

import xml.etree.ElementTree as ET
import os
from os import getcwd
from tqdm import tqdm
 
classes = ["helmet", "person"]
 
def convert(size, box):
    dw = 1. / size[0]
    dh = 1. / size[1]
    x = (box[0] + box[1]) / 2.0
    y = (box[2] + box[3]) / 2.0
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x * dw
    w = w * dw
    y = y * dh
    h = h * dh
    return (x, y, w, h)
 
def convert_annotation(image_id):
    in_file = './xml/%s.xml' % (image_id)
    out_file = open('./labels/%s.txt' % (image_id), 'w')
    tree = ET.parse(in_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
        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))
        bb = convert((w, h), b)
        out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
 
if __name__ == "__main__":
    wd = getcwd()
    print(wd)
    if not os.path.exists('./labels/'):
        os.makedirs('./labels/')
    image_ids = os.listdir('./datasets')
    for image_id in tqdm(image_ids):
        convert_annotation(image_id.split('.')[0])

你可能感兴趣的:(pip,pyqt)