Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Add feature select all, select multiple, drag multiple, and rotate #931

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Binary file added Builds/labelImg1.0.1.zip
Binary file not shown.
Binary file added Builds/labelImg1.0.2.zip
Binary file not shown.
Binary file added Builds/labelImg1.0.3.zip
Binary file not shown.
15 changes: 0 additions & 15 deletions data/predefined_classes.txt
Original file line number Diff line number Diff line change
@@ -1,15 +0,0 @@
dog
person
cat
tv
car
meatballs
marinara sauce
tomato soup
chicken noodle soup
french onion soup
chicken breast
ribs
pulled pork
hamburger
cavity
45 changes: 37 additions & 8 deletions labelImg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import argparse
import codecs
from operator import truediv
import os.path
import platform
import shutil
Expand Down Expand Up @@ -188,7 +189,7 @@ def __init__(self, default_filename=None, default_prefdef_class_file=None, defau
self.canvas.zoomRequest.connect(self.zoom_request)
self.canvas.lightRequest.connect(self.light_request)
self.canvas.set_drawing_shape_to_square(settings.get(SETTING_DRAW_SQUARE, False))

self.canvas.onStartAction.connect(self.saveHistoryBoxes)
scroll = QScrollArea()
scroll.setWidget(self.canvas)
scroll.setWidgetResizable(True)
Expand Down Expand Up @@ -242,6 +243,20 @@ def __init__(self, default_filename=None, default_prefdef_class_file=None, defau
save = action(get_str('save'), self.save_file,
'Ctrl+S', 'save', get_str('saveDetail'), enabled=False)

actionSelectAll = QAction( "Select all", self)
actionSelectAll.setShortcut("Ctrl+A")
def selectAll():
self.toggle_polygons(True)
self.canvas.selectAll()
actionSelectAll.triggered.connect(selectAll)
self.addAction(actionSelectAll)

#add action undo
# actionUndo =QAction("Undo", self)
# actionUndo.setShortcut("Ctrl+Z")
# actionUndo.triggered.connect(self.undoActions)
# self.addAction(actionUndo)

def get_format_meta(format):
"""
returns a tuple containing (title, icon_name) of the selected format
Expand Down Expand Up @@ -291,7 +306,7 @@ def get_format_meta(format):
'Ctrl+H', 'hide', get_str('hideAllBoxDetail'),
enabled=False)
show_all = action(get_str('showAllBox'), partial(self.toggle_polygons, True),
'Ctrl+A', 'hide', get_str('showAllBoxDetail'),
'Ctrl+I', 'hide', get_str('showAllBoxDetail'),
enabled=False)

help_default = action(get_str('tutorialDefault'), self.show_default_tutorial_dialog, None, 'help', get_str('tutorialDetail'))
Expand Down Expand Up @@ -540,13 +555,15 @@ def xbool(x):
self.open_dir_dialog(dir_path=self.file_path, silent=True)

def keyReleaseEvent(self, event):
if event.key() == Qt.Key_Control:
self.canvas.set_drawing_shape_to_square(False)
print("key release")
# if event.key() == Qt.Key_Control:
# self.canvas.set_drawing_shape_to_square(False)

def keyPressEvent(self, event):
if event.key() == Qt.Key_Control:
# Draw rectangle if Ctrl is pressed
self.canvas.set_drawing_shape_to_square(True)
print("key Pressed")
# if event.key() == Qt.Key_Control:
# # Draw rectangle if Ctrl is pressed
# self.canvas.set_drawing_shape_to_square(True)

# Support Functions #
def set_format(self, save_format):
Expand Down Expand Up @@ -1178,6 +1195,8 @@ def counter_str(self):
return '[{} / {}]'.format(self.cur_img_idx + 1, self.img_count)

def show_bounding_box_from_annotation_file(self, file_path):
if file_path is None:
return
if self.default_save_dir is not None:
basename = os.path.basename(os.path.splitext(file_path)[0])
xml_path = os.path.join(self.default_save_dir, basename + XML_EXT)
Expand Down Expand Up @@ -1205,7 +1224,6 @@ def show_bounding_box_from_annotation_file(self, file_path):
self.load_yolo_txt_by_filename(txt_path)
elif os.path.isfile(json_path):
self.load_create_ml_json_by_filename(json_path, file_path)


def resizeEvent(self, event):
if self.canvas and not self.image.isNull()\
Expand Down Expand Up @@ -1449,7 +1467,17 @@ def open_next_image(self, _value=False):

if filename:
self.load_file(filename)
def saveHistoryBoxes(self, firstTime = False):
pass
# for shape in self.canvas.shapes:
# shape.saveHistory()

def undoActions(self):
print("Undo")
for shape in self.canvas.shapes:
shape.undoAction()
self.canvas.update()

def open_file(self, _value=False):
if not self.may_continue():
return
Expand Down Expand Up @@ -1478,6 +1506,7 @@ def save_file(self, _value=False):
saved_path = os.path.join(image_file_dir, saved_file_name)
self._save_file(saved_path if self.label_file
else self.save_file_dialog(remove_ext=False))
self.saveHistoryBoxes()

def save_file_as(self, _value=False):
assert not self.image.isNull(), "cannot save empty image"
Expand Down
Loading