Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated version multi class no examples #23

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/Images
!/Images/001
File renamed without changes
File renamed without changes
Binary file removed Images/001/test.JPEG
Binary file not shown.
Binary file removed Images/001/test2.JPEG
Binary file not shown.
Binary file removed Images/001/test3.JPEG
Binary file not shown.
2 changes: 0 additions & 2 deletions Labels/001/test.txt

This file was deleted.

2 changes: 0 additions & 2 deletions Labels/001/test2.txt

This file was deleted.

2 changes: 0 additions & 2 deletions Labels/001/test3.txt

This file was deleted.

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
### Forked from [puzzledqs/BBox-Label-Tool](https://github.com/puzzledqs/BBox-Label-Tool)
## Improvements
1. Add multi-class support
2. Change some of the color-candidates for better display
3. Fix the 'Example' filepath for convenience
4. Change the image format from '.JPEG' to '.JPG'

## New Usage
### For multi-class task, modify 'class.txt' with your own class-candidates and before labeling bbox, choose the 'Current Class' in the Combobox and make sure you click 'ComfirmClass' button.

### The remaining usage is the same as the origin one.

------------------------------------

**Contact info**: jxgu1016@gmail.com

------------------------------------

BBox-Label-Tool
===============

Expand Down
133 changes: 133 additions & 0 deletions class.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
Pedestrian
Truck
Car
Cyclist
DontCare
Misc
Van
Tram
Person_sitting
Cat
Dog
Horse
Pram
Fence
Pole
Lamppost
Door
Window
Home/Facade
Max_speed_A01-5
Max_speed_A01-10
Max_speed_A01-15
Max_speed_A01-30
Max_speed_A01-50
Zone_max_speed_A01-30
Zone_max_speed_A01-60
End_max_speed_A02-30
End_max_speed_A02-50
End_zone_speed_A02-30
Priority_road
End_priority_road
Priority_crossing_point
Priority_crossing_point_side_left
Priority_crossing_point_side_right
Give_way_sign
Stop_sign
Deflective_priority_road_OB701-1
Deflective_priority_road_OB701-2
Deflective_priority_road_OB701-3
Deflective_priority_road_OB702-1
Deflective_priority_road_OB702-2
Deflective_priority_road_OB703-1
Deflective_priority_road_OB703-2
Closed_both_directions
One_way_street
One_way_road
One_way_road_left
One_way_road_right
One_way_road_left
Drive_in_allowed
Closed_for_motor_vehicles_on_two_plus_wheels
Closed_for_all_motor_vehicles
Zone_closed_for_motor_vehicles_on_two_plus_wheels
End_zone_closed_for_motor_vehicles
Zone_closed_for_all_motor_vehicles
End_zone_closed_for_all_motor_vehicles
Roundabout
Commandment_to_pass_sign_on_arrow_indication_D02-LO
Commandment_to_pass_sign_on_arrow_indication_D02-RO
Commandment_to_pass_sign_on_arrow_indication_D02-LB
Commandment_to_pass_sign_on_arrow_indication_D02-RB
Commandment_to_pass_sign_on_both_sides_of_arrow
Commandment_to_follow_sign_arrow_D04
Commandment_to_follow_sign_arrow_D05-L
Commandment_to_follow_sign_arrow_D05-R
Commandment_to_follow_sign_one_of_arrow_indication_D06-L
Commandment_to_follow_sign_one_of_arrow_indication_D06-R
Commandment_to_follow_sign_one_of_arrow_indication_D07
Scare_fence
Arch_left
Arch_right
Forbidden_to_park
Forbidden_to_stand_still
Zone_forbidden_to_park
End_zone_forbidden_to_park
Zone_forbidden_to_stand_still
End_zone_forbidden_to_stand_still
Prohibition_to_approach_traffic_out_of_opposite_direction
Drivers_from_counter-direction_need_to_give_priority_to_other_direction_drivers
Forbidden_to_turn
End_of_all_previous_indications
Stop_for_specified
Property
End_of_property
Sidewalk
End_of_sidewalk
Optional_bicycle_path
End_of_optional_bicycle_path
Obligated_bicycle_path
End_of_obligated_bicycle_path
Warning_for_bad_pavement
Warning_for_turn_right
Warning_for_turn_left
Warning_for_dangerous_intersection
Warning_for_roundabout
Warning_for_constructions
Warning_for_road_narrowing
Warning_for_road_narrowing_right
Warning_for_road_narrowing_left
Warning_for_children
Warning_for_pedestrian_crossing
Warning_for_pedestrians
Warning_for_bikers_and_mopeds
Warning_for_quay_or_river_banks
Warning_for_oncoming_traffic
Warning_for_traffic_lights
Warning_for_given_reason_under_sign
Warning_for_electric_and_extandable_pole_in_road_track
Pedestrian_crossing
Bus_stop_and_tram_stop
Tram_stop_and_bus_stop
Bus_stop
Tram_stop
Dead_end
Dead_end_with_left_way
Dead_end_with_right_way
Dead_end_left_with_straight_ahead_way
Dead_end_right_with_straight_ahead_way
Watch_out_bus_lane
Watch_out_speed_bumps
Bike_street_cars_allowed
Orange_pawn
Red_white_pawn
Guidance_beacon
Guidance_beacon_left
Guidance_beacon_right
Right_of_way_road_markings
Pedestrian_crossing_marking
Bicycle_lane
Bus_lane
Continious_lane
Parking_lots
Traffic_lights
108 changes: 108 additions & 0 deletions convert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# -*- coding: utf-8 -*-
"""
Created on Wed Dec 9 14:55:43 2015

This script is to convert the txt annotation files to appropriate format needed by YOLO

@author: Guanghan Ning
Email: gnxr9@mail.missouri.edu
"""

import os
import time
from os import walk, getcwd
from PIL import Image

classes = []

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)


"""-------------------------------------------------------------------"""

""" Configure Paths """
mypath = "Labels/002/"
outpath = "Labels/converted/{}/".format(int(time.time()))
class_loc = "class.txt"
images_path = 'Images/002/%s.JPG'
os.makedirs(outpath)

""" Load classes """
with open(class_loc) as classes_f:
for c in classes_f:
classes.append(c.replace('\n', ''))
print("Loaded classes: ", classes)
list_file = open('list.txt', 'w+')

""" Get input text file list """
txt_name_list = []
for (dirpath, dirnames, filenames) in walk(mypath):
txt_name_list.extend(filenames)
break
print(txt_name_list)

""" Process """
for txt_name in txt_name_list:
# txt_file = open("Labels/stop_sign/001.txt", "r")

""" Open input text files """
txt_path = mypath + txt_name
print("Input:" + txt_path)
txt_file = open(txt_path, "r")
lines = txt_file.read().split('\n') #for ubuntu, use "\r\n" instead of "\n"

""" Open output text files """
txt_outpath = outpath + txt_name
print("Output:" + txt_outpath)
txt_outfile = open(txt_outpath, "w")


""" Convert the data to YOLO format """
ct = 0
for line in lines:
#print('lenth of line is: ')
#print(len(line))
#print('\n')
if(len(line) >= 2):
ct = ct + 1
print(line + "\n")
elems = line.split(' ')
print(elems)
xmin = elems[0]
xmax = elems[2]
ymin = elems[1]
ymax = elems[3]
cls = elems[4]
#
img_path = str(images_path % (os.path.splitext(txt_name)[0]))
#t = magic.from_file(img_path)
#wh= re.search('(\d+) x (\d+)', t).groups()
im=Image.open(img_path)
w = int(im.size[0])
h = int(im.size[1])
#w = int(xmax) - int(xmin)
#h = int(ymax) - int(ymin)
# print(xmin)
print(w, h)
b = (float(xmin), float(xmax), float(ymin), float(ymax))
bb = convert((w,h), b)
print(bb)
cls_id = classes.index(cls)
txt_outfile.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')

""" Save those images with bb into list"""
if(ct != 0):
list_file.write('Images/%s.JPG\n'%(os.path.splitext(txt_name)[0]))

list_file.close()
3 changes: 3 additions & 0 deletions list.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Images/000008.JPG
Images/000000.JPG
Images/007480.JPG
Loading