Cartucho / OpenLabeling

Label images and video for Computer Vision applications

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Load Labels from external files

Mewiss opened this issue · comments

Hi!

I'm working on labeling multiple images with a team, so I receive their *.txt files with the labels. The problem is when I try to watch the marks from an external PC, so I copy the .txt file in the output folder, I can't see this when I run OpenLabeling. Does it use PASCAL files to draw? Is there any way I can load my label's data to OpenLabeling?

Thanks!

Hello!

Yeah, currently it is using the ones from PASCAL to draw.
Previously someone mentioned that they would implement the code for it to draw from the YOLO format as well (#59). But I guess that user got busy and never had time for it.

If I have time this week, I will implement it myself and I will let you know.

Thanks for your answer.
I implemented it as follow:

First, I modified method draw_bboxes_from_file

  def draw_bboxes_from_file(tmp_img, annotation_paths, width, height):
    global img_objects#, is_bbox_selected, selected_bbox
    img_objects = []
    yolo_file = next(path for path in annotation_paths if 'YOLO_darknet' in path)
    if os.path.isfile(yolo_file):
        detection_file = open(yolo_file,'r')
        reader = csv.DictReader(detection_file, fieldnames=["classId","centerX","centerY","width","height"], delimiter=' ')
        for idx, obj in enumerate(reader):
            class_name, class_index, xmin, ymin, xmax, ymax = get_txt_object_data(obj,width, height)
            #print('{} {} {} {} {}'.format(class_index, xmin, ymin, xmax, ymax))
            img_objects.append([class_index, xmin, ymin, xmax, ymax])
[...]

Also, I created get_txt_object_data method

def get_txt_object_data(obj,width_, height_):
    width   = float( obj['width']   ) #* image_width
    height  = float( obj['height']  ) #* image_height
    centerX = float( obj['centerX'] ) #* image_width
    centerY = float( obj['centerY'] ) #* image_height

    class_index = int(obj['classId'])
    class_name = CLASS_LIST[class_index]
    xmin = int(width_ * (centerX - width/2))
    xmax = int(width_ * (centerX + width/2))
    ymin = int(height_ * (centerY - height/2 ))
    ymax = int(height_ * (centerY + height/2))
    return [class_name, class_index, xmin, ymin, xmax, ymax]

Finally, note that it requires an import csv

Maybe it would be great to incorporate it with a flag in order to select which kind of file is read.

Regards!

Wonderful!
I will add it to the main code with a flag!

Done! based on your code, I added that functionality! I made it so it would not need that extra library to be imported. Thanks again.