|
@@ -227,6 +227,8 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
|
|
|
list_label_->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
list_areas_ = new QListWidget(central_widget_);
|
|
|
list_areas_->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
+ list_images_widget_ = new QListWidget(central_widget_);
|
|
|
+ //list_images_widget_->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
// addLabel(0, false, "BACKGROUND");
|
|
|
// list_label_->item(0)->setFlags(Qt::ItemIsSelectable);
|
|
|
//QListWidgetItem *background = list_label_->item(0);
|
|
@@ -234,7 +236,8 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
|
|
|
//background->setFlags(Qt::ItemIsSelectable);
|
|
|
|
|
|
label_toolbox_ = new QLabel(tr("Tool box"), frame_toolbox_);
|
|
|
- label_list_areas_ = new QLabel(tr("Selected areas"), central_widget_);
|
|
|
+ label_list_areas_ = new QLabel(tr("Selected areas:"), central_widget_);
|
|
|
+ label_list_images_ = new QLabel(tr("Loaded images:"), central_widget_);
|
|
|
|
|
|
/* buttons */
|
|
|
button_bound_box_tool_ = new QPushButton(frame_toolbox_);
|
|
@@ -315,6 +318,10 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
|
|
|
layout_toolbox_->addSpacing(10);
|
|
|
layout_toolbox_->addWidget(button_generate_colors_);
|
|
|
/* stretch is for making toolbox as small as it can be */
|
|
|
+ layout_toolbox_->addSpacing(10);
|
|
|
+ layout_left_->addWidget(label_list_images_);
|
|
|
+ layout_left_->addWidget(list_images_widget_);
|
|
|
+ list_images_widget_->setFixedWidth(200);
|
|
|
layout_left_->addStretch(1);
|
|
|
layout_left_->addWidget(button_confirm_selection_);
|
|
|
|
|
@@ -341,7 +348,7 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
|
|
|
|
|
|
/* right part */
|
|
|
layout_right_->addWidget(frame_labelbox_);
|
|
|
- frame_labelbox_->setFixedWidth(300);
|
|
|
+ frame_labelbox_->setFixedWidth(200);
|
|
|
frame_labelbox_->setLayout(layout_labelbox_);
|
|
|
|
|
|
layout_labelbox_->addLayout(layout_labelbox_buttons_);
|
|
@@ -531,6 +538,12 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
|
|
|
this,
|
|
|
SLOT(labelListPopupMenu(const QPoint &))
|
|
|
);
|
|
|
+ connect(
|
|
|
+ list_images_widget_,
|
|
|
+ SIGNAL(itemDoubleClicked(QListWidgetItem *)),
|
|
|
+ this,
|
|
|
+ SLOT(selectImage(QListWidgetItem *))
|
|
|
+ );
|
|
|
connect(
|
|
|
action_delete_area_,
|
|
|
SIGNAL(triggered()),
|
|
@@ -658,8 +671,10 @@ ImageLabeler::~ImageLabeler()
|
|
|
|
|
|
delete label_list_areas_;
|
|
|
delete label_toolbox_;
|
|
|
+ delete label_list_images_;
|
|
|
delete list_areas_;
|
|
|
delete list_label_;
|
|
|
+ delete list_images_widget_;
|
|
|
|
|
|
delete layout_toolbox_;
|
|
|
delete layout_right_;
|
|
@@ -677,14 +692,28 @@ ImageLabeler::~ImageLabeler()
|
|
|
delete frame_center_;
|
|
|
|
|
|
delete central_widget_;
|
|
|
-
|
|
|
- delete list_images_;
|
|
|
//delete current_image_;
|
|
|
|
|
|
if (pure_data_) {
|
|
|
delete[] *pure_data_;
|
|
|
delete pure_data_;
|
|
|
}
|
|
|
+
|
|
|
+ delete list_images_;
|
|
|
+}
|
|
|
+
|
|
|
+void
|
|
|
+ImageLabeler::addImage(QString *anImage)
|
|
|
+{
|
|
|
+ QListWidgetItem *newItem = new QListWidgetItem;
|
|
|
+
|
|
|
+ QString itemText = QString("%1: %2").
|
|
|
+ arg(list_images_widget_->count()).
|
|
|
+ arg(getFilenameFromPath(anImage));
|
|
|
+ newItem->setText(itemText);
|
|
|
+
|
|
|
+ list_images_widget_->addItem(newItem);
|
|
|
+ list_images_->append(*anImage);
|
|
|
}
|
|
|
|
|
|
void
|
|
@@ -723,6 +752,7 @@ ImageLabeler::addLabel()
|
|
|
|
|
|
list_label_->addItem(newItem);
|
|
|
list_label_->setItemSelected(newItem, true);
|
|
|
+ label_ID_ = list_label_->count() - 1;
|
|
|
|
|
|
unsaved_data_ = 1;
|
|
|
}
|
|
@@ -1143,8 +1173,12 @@ ImageLabeler::getImagesFromDir(const QDir &dir)
|
|
|
QStringList listImages =
|
|
|
dir.entryList(filenameFilter, QDir::Files);
|
|
|
|
|
|
- foreach (QString file, listImages)
|
|
|
- list_images_->append(dir.absoluteFilePath(file));
|
|
|
+ foreach (QString file, listImages) {
|
|
|
+ QString itemText = dir.absoluteFilePath(file);
|
|
|
+ addImage(&itemText);
|
|
|
+ //list_label_->setItemSelected(newItem, true);
|
|
|
+ //list_images_->append(dir.absoluteFilePath(file));
|
|
|
+ }
|
|
|
|
|
|
QStringList listDir = dir.entryList(QDir::Dirs);
|
|
|
foreach (QString subdir, listDir) {
|
|
@@ -1167,22 +1201,28 @@ ImageLabeler::nextImage()
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
|
|
|
|
- if (list_images_->end() == current_image_ + 1)
|
|
|
- current_image_ = list_images_->begin();
|
|
|
- else
|
|
|
- current_image_++;
|
|
|
+ if (list_images_widget_->count() - 1 == image_ID_) {
|
|
|
+ current_image_ = list_images_->at(0);
|
|
|
+ image_ID_ = 0;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ image_ID_ ++;
|
|
|
+ current_image_ = list_images_->at(image_ID_);
|
|
|
+ }
|
|
|
+
|
|
|
+ list_images_widget_->setCurrentRow(image_ID_);
|
|
|
|
|
|
- if ((*current_image_).isEmpty()) {
|
|
|
+ if (current_image_.isEmpty()) {
|
|
|
return;
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
|
|
|
|
QString winTitle;
|
|
|
winTitle.append("ImageLabeler - ");
|
|
|
- winTitle.append(*current_image_);
|
|
|
+ winTitle.append(current_image_);
|
|
|
setWindowTitle(winTitle);
|
|
|
|
|
|
- image_->load(*current_image_);
|
|
|
+ image_->load(current_image_);
|
|
|
image_holder_->resize(image_->size());
|
|
|
image_holder_->setPixmap(*image_);
|
|
|
list_bounding_box_.clear();
|
|
@@ -1196,7 +1236,7 @@ ImageLabeler::nextImage()
|
|
|
void
|
|
|
ImageLabeler::prevImage()
|
|
|
{
|
|
|
- if (list_images_->isEmpty()) {
|
|
|
+ if (!list_images_widget_->count()) {
|
|
|
return;
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
@@ -1206,17 +1246,23 @@ ImageLabeler::prevImage()
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
|
|
|
|
- if (list_images_->begin() == current_image_)
|
|
|
- current_image_ = list_images_->end() - 1;
|
|
|
- else
|
|
|
- current_image_--;
|
|
|
+ if (!image_ID_) {
|
|
|
+ image_ID_ = list_images_widget_->count() - 1;
|
|
|
+ current_image_ = list_images_->at(image_ID_);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ image_ID_--;
|
|
|
+ current_image_ = list_images_->at(image_ID_);
|
|
|
+ }
|
|
|
+
|
|
|
+ list_images_widget_->setCurrentRow(image_ID_);
|
|
|
|
|
|
QString winTitle;
|
|
|
winTitle.append("ImageLabeler - ");
|
|
|
- winTitle.append(*current_image_);
|
|
|
+ winTitle.append(current_image_);
|
|
|
setWindowTitle(winTitle);
|
|
|
|
|
|
- image_->load(*current_image_);
|
|
|
+ image_->load(current_image_);
|
|
|
image_holder_->resize(image_->size());
|
|
|
image_holder_->setPixmap(*image_);
|
|
|
list_bounding_box_.clear();
|
|
@@ -1230,7 +1276,7 @@ ImageLabeler::prevImage()
|
|
|
void
|
|
|
ImageLabeler::saveAllInfo()
|
|
|
{
|
|
|
- if (list_images_->isEmpty()) {
|
|
|
+ if (!list_images_widget_->count()) {
|
|
|
showWarning("You have not opened any image yet");
|
|
|
return;
|
|
|
/* NOTREACHED */
|
|
@@ -1246,7 +1292,7 @@ ImageLabeler::saveAllInfo()
|
|
|
QDomElement image = doc.createElement(tr("image"));
|
|
|
root.appendChild(image);
|
|
|
|
|
|
- QDomText pathToImage = doc.createTextNode(*current_image_);
|
|
|
+ QDomText pathToImage = doc.createTextNode(current_image_);
|
|
|
image.appendChild(pathToImage);
|
|
|
|
|
|
if (!segmented_image_.isEmpty()) {
|
|
@@ -1293,10 +1339,10 @@ ImageLabeler::saveAllInfo()
|
|
|
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
fileDialog.setDefaultSuffix("dat");
|
|
|
fileDialog.setFileMode(QFileDialog::AnyFile);
|
|
|
- QString dir = getDirFromPath(&(*current_image_));
|
|
|
+ QString dir = getDirFromPath(¤t_image_);
|
|
|
|
|
|
/* altering the name of a new file */
|
|
|
- QString newFileName = alterFileName(*current_image_, "_labeled");
|
|
|
+ QString newFileName = alterFileName(current_image_, "_labeled");
|
|
|
|
|
|
fileDialog.selectFile(newFileName);
|
|
|
|
|
@@ -1348,10 +1394,10 @@ ImageLabeler::saveSegmentedPicture()
|
|
|
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
fileDialog.setDefaultSuffix("png");
|
|
|
fileDialog.setFileMode(QFileDialog::AnyFile);
|
|
|
- QString dir = getDirFromPath(&(*current_image_));
|
|
|
+ QString dir = getDirFromPath(¤t_image_);
|
|
|
|
|
|
/* altering the name of a new file */
|
|
|
- QString newFileName = alterFileName(*current_image_, "_segmented");
|
|
|
+ QString newFileName = alterFileName(current_image_, "_segmented");
|
|
|
|
|
|
fileDialog.selectFile(newFileName);
|
|
|
|
|
@@ -1446,10 +1492,10 @@ ImageLabeler::saveLegend()
|
|
|
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
fileDialog.setDefaultSuffix("dat");
|
|
|
fileDialog.setFileMode(QFileDialog::AnyFile);
|
|
|
- QString dir = getDirFromPath(&(*current_image_));
|
|
|
+ QString dir = getDirFromPath(¤t_image_);
|
|
|
|
|
|
/* altering the name of a new file */
|
|
|
- QString newFileName = alterFileName(*current_image_, "_legend");
|
|
|
+ QString newFileName = alterFileName(current_image_, "_legend");
|
|
|
|
|
|
fileDialog.selectFile(newFileName);
|
|
|
|
|
@@ -1546,16 +1592,17 @@ ImageLabeler::loadInfo()
|
|
|
return;
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
|
- list_images_->append(string);
|
|
|
- current_image_ = list_images_->end();
|
|
|
- current_image_--;
|
|
|
+ addImage(&string);
|
|
|
+ current_image_ = string;
|
|
|
+ image_ID_ = list_images_widget_->count() - 1;
|
|
|
+ list_images_widget_->setCurrentRow(image_ID_);
|
|
|
|
|
|
QString winTitle;
|
|
|
winTitle.append("ImageLabeler - ");
|
|
|
- winTitle.append(*current_image_);
|
|
|
+ winTitle.append(current_image_);
|
|
|
setWindowTitle(winTitle);
|
|
|
|
|
|
- image_->load(*current_image_);
|
|
|
+ image_->load(current_image_);
|
|
|
image_holder_->resize(image_->size());
|
|
|
image_holder_->setPixmap(*image_);
|
|
|
}
|
|
@@ -1648,22 +1695,23 @@ ImageLabeler::loadImage()
|
|
|
clearAllTool();
|
|
|
|
|
|
|
|
|
- list_images_->append(filename);
|
|
|
+ addImage(&filename);
|
|
|
|
|
|
- if (list_images_->isEmpty()) {
|
|
|
+ if (!list_images_widget_->count()) {
|
|
|
return;
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
|
|
|
|
- current_image_ = list_images_->end();
|
|
|
- current_image_--;
|
|
|
+ current_image_ = filename;
|
|
|
+ image_ID_ = list_images_widget_->count() - 1;
|
|
|
+ list_images_widget_->setCurrentRow(image_ID_);
|
|
|
|
|
|
QString winTitle;
|
|
|
winTitle.append("ImageLabeler - ");
|
|
|
- winTitle.append(*current_image_);
|
|
|
+ winTitle.append(current_image_);
|
|
|
setWindowTitle(winTitle);
|
|
|
|
|
|
- image_->load(*current_image_);
|
|
|
+ image_->load(current_image_);
|
|
|
image_holder_->resize(image_->size());
|
|
|
image_holder_->setPixmap(*image_);
|
|
|
|
|
@@ -1724,20 +1772,22 @@ ImageLabeler::loadImages()
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
|
|
|
|
- if (list_images_->isEmpty()) {
|
|
|
+ if (!list_images_widget_->count()) {
|
|
|
showWarning(tr("The folder you selected contains no images"));
|
|
|
return;
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
|
|
|
|
- current_image_ = list_images_->begin();
|
|
|
+ current_image_ = list_images_->at(0);
|
|
|
+ image_ID_ = 0;
|
|
|
+ list_images_widget_->setCurrentRow(image_ID_);
|
|
|
|
|
|
QString winTitle;
|
|
|
winTitle.append("ImageLabeler - ");
|
|
|
- winTitle.append(*current_image_);
|
|
|
+ winTitle.append(current_image_);
|
|
|
setWindowTitle(winTitle);
|
|
|
|
|
|
- image_->load(*current_image_);
|
|
|
+ image_->load(current_image_);
|
|
|
image_holder_->resize(image_->size());
|
|
|
image_holder_->setPixmap(*image_);
|
|
|
|
|
@@ -2399,6 +2449,7 @@ ImageLabeler::clearAll()
|
|
|
list_bounding_box_.clear();
|
|
|
list_polygon_.clear();
|
|
|
list_images_->clear();
|
|
|
+ list_images_widget_->clear();
|
|
|
main_label_ = -1;
|
|
|
image_holder_->clearAll();
|
|
|
segmented_image_.clear();
|
|
@@ -2619,12 +2670,12 @@ ImageLabeler::onOptionsSet()
|
|
|
void
|
|
|
ImageLabeler::viewNormal()
|
|
|
{
|
|
|
- if ((*current_image_).isEmpty()) {
|
|
|
+ if (current_image_.isEmpty()) {
|
|
|
return;
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
|
|
|
|
- image_->load(*current_image_);
|
|
|
+ image_->load(current_image_);
|
|
|
image_holder_->setPixmap(*image_);
|
|
|
|
|
|
action_view_segmented_->setEnabled(true);
|
|
@@ -2652,6 +2703,21 @@ ImageLabeler::interruptSearch()
|
|
|
interrupt_search_ = 1;
|
|
|
}
|
|
|
|
|
|
+void
|
|
|
+ImageLabeler::selectImage(QListWidgetItem *anItem)
|
|
|
+{
|
|
|
+ if (!anItem || list_images_widget_->row(anItem) < 0) {
|
|
|
+ return;
|
|
|
+ /* NOTREACHED */
|
|
|
+ }
|
|
|
+
|
|
|
+ image_ID_ = list_images_widget_->row(anItem);
|
|
|
+
|
|
|
+ image_->load(list_images_->at(image_ID_));
|
|
|
+ image_holder_->setPixmap(*image_);
|
|
|
+ image_holder_->resize(image_->size());
|
|
|
+}
|
|
|
+
|
|
|
void
|
|
|
ImageLabeler::resizeEvent (QResizeEvent *anEvent)
|
|
|
{
|
|
@@ -2667,13 +2733,15 @@ ImageLabeler::mousePressEvent(QMouseEvent *anEvent)
|
|
|
void
|
|
|
ImageLabeler::keyPressEvent(QKeyEvent *anEvent)
|
|
|
{
|
|
|
+ keyboard_modifier_ = anEvent->modifiers();
|
|
|
+
|
|
|
if (Qt::Key_Left == anEvent->key() &&
|
|
|
- Qt::NoModifier == anEvent->modifiers()) {
|
|
|
+ Qt::ControlModifier == keyboard_modifier_) {
|
|
|
prevImage();
|
|
|
}
|
|
|
|
|
|
if (Qt::Key_Right == anEvent->key() &&
|
|
|
- Qt::NoModifier == anEvent->modifiers()) {
|
|
|
+ Qt::ControlModifier == keyboard_modifier_) {
|
|
|
nextImage();
|
|
|
}
|
|
|
|
|
@@ -2717,11 +2785,13 @@ void
|
|
|
ImageLabeler::wheelEvent(QWheelEvent *anEvent)
|
|
|
{
|
|
|
/* zoomin */
|
|
|
- if (0 < anEvent->delta()) {
|
|
|
+ if (0 < anEvent->delta() &&
|
|
|
+ Qt::ControlModifier == keyboard_modifier_) {
|
|
|
image_holder_->scaleImage(ZoomIn, 1.1);
|
|
|
}
|
|
|
/* zoomout */
|
|
|
- else if (anEvent->delta() < 0) {
|
|
|
+ else if (anEvent->delta() < 0 &&
|
|
|
+ Qt::ControlModifier == keyboard_modifier_) {
|
|
|
image_holder_->scaleImage(ZoomOut, 1.1);
|
|
|
}
|
|
|
}
|