Skip to content

Commit

Permalink
added autolabbler flags
Browse files Browse the repository at this point in the history
  • Loading branch information
electro199 committed Aug 24, 2024
1 parent 03a61c3 commit b9b8dd2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 37 deletions.
58 changes: 27 additions & 31 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

from PySide6.QtGui import QImageReader, QPixmap, QShortcut, QClipboard
from PySide6.QtCore import Qt
from auto_labeler import Auto_Labbeler
from ui.app_ui import Ui_MainWindow
from ui.custom_input_iu import InputDialog
from glob import glob
import csv
import logging

Auto_Labbeler_ENABLED = False

if Auto_Labbeler_ENABLED:
from auto_labeler import Auto_Labbeler
class App(QMainWindow):
def __init__(self):
super().__init__()
Expand Down Expand Up @@ -55,29 +57,35 @@ def __init__(self):
self.ui.image_area.customContextMenuRequested.connect(self.show_context_menu)

self.ui.actionopen_folder.triggered.connect(self.open_folder)
self.ui.actionOpen_img_csv.triggered.connect(self.open_img_csv)
self.ui.actionOpen_Labels_file.triggered.connect(self.get_labels)
self.ui.add_Label.pressed.connect(self._add_label_manual)

self.ui.actionSave_project.triggered.connect(self.savedataset)
self.ui.actionOpen_img_csv.triggered.connect(self.open_img_csv)
self.ui.actionsave_dataset.triggered.connect(self.save_progress_file)
self.ui.actionsave_progress.triggered.connect(self.save_progress_file)
self.ui.actionload_from_progress_file.triggered.connect(
self.load_from_progress_file
)
self.ui.add_Label.pressed.connect(self._add_label_manual)

shortcut_a = QShortcut(QKeySequence(Qt.Key_A), self) # type: ignore
shortcut_a.activated.connect(self.on_a_key_pressed)

shortcut_d = QShortcut(QKeySequence(Qt.Key_D), self) # type: ignore
shortcut_d.activated.connect(self.on_d_key_pressed)

self.model = Auto_Labbeler()
self.model.result_signal.connect(self.set_label)
if Auto_Labbeler_ENABLED:
self.model = Auto_Labbeler()
self.model.result_signal.connect(self.set_label)


@Slot(str)
def set_label(self,text):
if not text:
self.ui.current_image_path_label.setText("No Label")
if Auto_Labbeler_ENABLED:
self.model.set_image_path(self.current_image)
self.model.start()
return

self.ui.current_image_path_label.setText(text)

@property
Expand All @@ -88,7 +96,6 @@ def current_image_index(self) -> int:
def current_image_index(self, num) -> None:
self.__current_image_index = num
self.ui.progressBar.setValue(num + 1)
# self.ui.progressBar.
self.ui.progressBar.setMaximum(len(self.all_images_path))

def show_context_menu(self, position) -> None:
Expand Down Expand Up @@ -154,21 +161,18 @@ def show_next_image(self,) -> None:
str(Path(__file__).parent.joinpath("icons", "empty-icon.jpg"))
)
return
else:
self.current_image = self.all_images_path[self.current_image_index + 1]
image_reader = QImageReader(self.current_image)
# try:
if self.all_labels[self.current_image_index + 1]:
self.set_label(self.all_labels[self.current_image_index + 1])
else:

self.model.set_image_path(self.current_image)
self.model.start()

self.current_image_index += 1

self.current_image = self.all_images_path[self.current_image_index]
image_reader = QImageReader(self.current_image)
# try:

self.set_label(self.all_labels[self.current_image_index])

logging.debug(self.current_image)

pixmap = QPixmap.fromImageReader(image_reader)
self.current_image_index += 1

if pixmap.isNull():
logging.info("found broken image", self.current_image)
Expand All @@ -182,22 +186,14 @@ def show_previous_image(self) -> None:
if self.current_image_index - 1 < 0:
return

self.current_image_index -= 1

self.current_image = self.all_images_path[self.current_image_index - 1]
self.current_image = self.all_images_path[self.current_image_index]
image_reader = QImageReader(self.current_image)

self.set_label(self.all_labels[self.current_image_index - 1])
# try:
# logging.info(
# self.ui.current_image_path_label.setText(
# self.all_labels[self.current_image_index - 1]
# ),
# self.current_image,
# )
# except IndexError:
# self.ui.current_image_path_label.setText("No Label")
self.set_label(self.all_labels[self.current_image_index])

pixmap = QPixmap.fromImageReader(image_reader)
self.current_image_index -= 1

if pixmap.isNull():
logging.info("found broken image", self.current_image)
Expand Down
4 changes: 2 additions & 2 deletions ui/app.ui
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ background-color:rgb(0,255,0)
<addaction name="actionOpen_Labels_file"/>
<addaction name="separator"/>
<addaction name="actionSave_project"/>
<addaction name="actionsave_dataset"/>
<addaction name="actionsave_progress"/>
<addaction name="actionload_from_progress_file"/>
</widget>
<addaction name="menuFile"/>
Expand All @@ -208,7 +208,7 @@ background-color:rgb(0,255,0)
<string>Open img csv</string>
</property>
</action>
<action name="actionsave_dataset">
<action name="actionsave_progress">
<property name="text">
<string>save_progress</string>
</property>
Expand Down
8 changes: 4 additions & 4 deletions ui/app_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def setupUi(self, MainWindow):
self.actionSave_project.setObjectName(u"actionSave_project")
self.actionOpen_img_csv = QAction(MainWindow)
self.actionOpen_img_csv.setObjectName(u"actionOpen_img_csv")
self.actionsave_dataset = QAction(MainWindow)
self.actionsave_dataset.setObjectName(u"actionsave_dataset")
self.actionsave_progress = QAction(MainWindow)
self.actionsave_progress.setObjectName(u"actionsave_progress")
self.actionload_from_progress_file = QAction(MainWindow)
self.actionload_from_progress_file.setObjectName(u"actionload_from_progress_file")
self.centralwidget = QWidget(MainWindow)
Expand Down Expand Up @@ -133,7 +133,7 @@ def setupUi(self, MainWindow):
self.menuFile.addAction(self.actionOpen_Labels_file)
self.menuFile.addSeparator()
self.menuFile.addAction(self.actionSave_project)
self.menuFile.addAction(self.actionsave_dataset)
self.menuFile.addAction(self.actionsave_progress)
self.menuFile.addAction(self.actionload_from_progress_file)

self.retranslateUi(MainWindow)
Expand All @@ -147,7 +147,7 @@ def retranslateUi(self, MainWindow):
self.actionOpen_Labels_file.setText(QCoreApplication.translate("MainWindow", u"Open Labels file", None))
self.actionSave_project.setText(QCoreApplication.translate("MainWindow", u"Save dataset", None))
self.actionOpen_img_csv.setText(QCoreApplication.translate("MainWindow", u"Open img csv", None))
self.actionsave_dataset.setText(QCoreApplication.translate("MainWindow", u"save_progress", None))
self.actionsave_progress.setText(QCoreApplication.translate("MainWindow", u"save_progress", None))
self.actionload_from_progress_file.setText(QCoreApplication.translate("MainWindow", u"load from progress file", None))
self.add_Label.setText(QCoreApplication.translate("MainWindow", u"Add Label", None))
self.current_image_path_label.setText("")
Expand Down

0 comments on commit b9b8dd2

Please sign in to comment.