|
@@ -17,6 +17,7 @@
|
|
|
#include <QGridLayout>
|
|
|
#include <QPixmap>
|
|
|
#include <QLabel>
|
|
|
+#include <QScrollArea>
|
|
|
#include <QPushButton>
|
|
|
#include <QButtonGroup>
|
|
|
#include <QListWidget>
|
|
@@ -176,11 +177,14 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
|
|
|
frame_center_ = new QFrame(central_widget_);
|
|
|
//frame_image_->setFrameStyle(QFrame::Box | QFrame::Plain);
|
|
|
//frame_image_->setLineWidth(1);
|
|
|
- frame_image_ = new QFrame(frame_center_);
|
|
|
+ frame_image_ = new QScrollArea(frame_center_);
|
|
|
//frame_image_->setStyleSheet("QWidget {background: #888888;}");
|
|
|
frame_image_->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
|
|
|
frame_image_->setLineWidth(0);
|
|
|
frame_image_->setMidLineWidth(0);
|
|
|
+ frame_image_->setWidgetResizable(false);
|
|
|
+ frame_image_->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
|
|
|
+ frame_image_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
|
frame_labelbox_ = new QFrame(central_widget_);
|
|
|
frame_labelbox_->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
|
|
|
frame_labelbox_->setLineWidth(0);
|
|
@@ -190,17 +194,19 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
|
|
|
image_->fill(QColor(Qt::white));
|
|
|
|
|
|
//image_holder_ = new ImageHolder(frame_image_);
|
|
|
- image_holder_ = new ImageHolder(frame_image_);
|
|
|
+ image_holder_ = new ImageHolder;//(frame_image_);
|
|
|
image_holder_->setPixmap(*image_);
|
|
|
- image_holder_->setStyleSheet("QLabel {background: #ffffff;}");
|
|
|
+ //image_holder_->setStyleSheet("QLabel {background: #ffffff;}");
|
|
|
image_holder_->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
|
|
|
- image_holder_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
|
+ image_holder_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
|
|
image_holder_->setFocusPolicy(Qt::StrongFocus);
|
|
|
image_holder_->setFocus();
|
|
|
- //image_holder_->setScaledContents(true);
|
|
|
+ image_holder_->setScaledContents(true);
|
|
|
image_holder_->setFrameStyle(QFrame::Box | QFrame::Plain);
|
|
|
image_holder_->setLineWidth(0);
|
|
|
|
|
|
+ frame_image_->setWidget(image_holder_);
|
|
|
+
|
|
|
list_label_ = new QListWidget(central_widget_);
|
|
|
list_label_->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
list_areas_ = new QListWidget(central_widget_);
|
|
@@ -305,12 +311,12 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
|
|
|
layout_frame_image_->setContentsMargins(0, 0, 0, 0);
|
|
|
layout_frame_image_->addWidget(frame_image_);
|
|
|
|
|
|
- frame_image_->setLayout(layout_image_widget_);
|
|
|
- layout_image_widget_->setRowStretch(0, 1);
|
|
|
- layout_image_widget_->setColumnStretch(0, 1);
|
|
|
- layout_image_widget_->addWidget(image_holder_, 1, 1);
|
|
|
- layout_image_widget_->setRowStretch(2, 1);
|
|
|
- layout_image_widget_->setColumnStretch(2, 1);
|
|
|
+ //frame_image_->setLayout(layout_image_widget_);
|
|
|
+// layout_image_widget_->setRowStretch(0, 1);
|
|
|
+// layout_image_widget_->setColumnStretch(0, 1);
|
|
|
+// layout_image_widget_->addWidget(image_holder_, 1, 1);
|
|
|
+// layout_image_widget_->setRowStretch(2, 1);
|
|
|
+// layout_image_widget_->setColumnStretch(2, 1);
|
|
|
|
|
|
//layout_frame_image_->addStretch(1);
|
|
|
layout_frame_image_->addLayout(layout_center_buttons_);
|
|
@@ -539,6 +545,7 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
|
|
|
image_holder_->setPolygonList(&list_polygon_);
|
|
|
image_holder_->setLabelColorList(&list_label_colors_);
|
|
|
image_holder_->setMainLabelNum(&main_label_);
|
|
|
+ image_holder_->setImage(image_);
|
|
|
}
|
|
|
|
|
|
ImageLabeler::~ImageLabeler()
|
|
@@ -647,9 +654,14 @@ ImageLabeler::addLabel()
|
|
|
newItem->setText(label);
|
|
|
|
|
|
QPixmap iconPix = QPixmap(20, 20);
|
|
|
- iconPix.fill(Qt::white);
|
|
|
+ QColor color;
|
|
|
+ if (0 != itemNum)
|
|
|
+ color = Qt::white;
|
|
|
+ else
|
|
|
+ color = Qt::black;
|
|
|
+ iconPix.fill(color);
|
|
|
QIcon icon(iconPix);
|
|
|
- list_label_colors_.append(0xffffffff);
|
|
|
+ list_label_colors_.append(color.rgb());
|
|
|
|
|
|
newItem->setIcon(icon);
|
|
|
|
|
@@ -734,18 +746,20 @@ ImageLabeler::removeLabel()
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
|
|
|
|
- QListWidgetItem *current = list_label_->currentItem();
|
|
|
-
|
|
|
- /* because we need to keep BACKGROUND category */
|
|
|
- if (0 == list_label_->row(current)) {
|
|
|
+ //QListWidgetItem *current = list_label_->currentItem();
|
|
|
+ /* we need to keep BACKGROUND category */
|
|
|
+ if (label_ID_ < 1) {
|
|
|
return;
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
|
|
|
|
- int row = list_label_->row(current);
|
|
|
- list_label_->takeItem(row);
|
|
|
- list_label_colors_.takeAt(row);
|
|
|
- delete current;
|
|
|
+ if (list_label_->count() <= label_ID_ ||
|
|
|
+ list_label_colors_.count() <= label_ID_) {
|
|
|
+ return;
|
|
|
+ /* NOTREACHED */
|
|
|
+ }
|
|
|
+ list_label_->takeItem(label_ID_);
|
|
|
+ list_label_colors_.takeAt(label_ID_);
|
|
|
}
|
|
|
|
|
|
void
|
|
@@ -1036,7 +1050,13 @@ ImageLabeler::nextImage()
|
|
|
current_image_ = list_images_->begin();
|
|
|
else
|
|
|
current_image_++;
|
|
|
+
|
|
|
+ if ((*current_image_).isEmpty()) {
|
|
|
+ return;
|
|
|
+ /* NOTREACHED */
|
|
|
+ }
|
|
|
image_->load(*current_image_);
|
|
|
+ image_holder_->resize(image_->size());
|
|
|
image_holder_->setPixmap(*image_);
|
|
|
list_bounding_box_.clear();
|
|
|
list_polygon_.clear();
|
|
@@ -1064,6 +1084,7 @@ ImageLabeler::prevImage()
|
|
|
else
|
|
|
current_image_--;
|
|
|
image_->load(*current_image_);
|
|
|
+ image_holder_->resize(image_->size());
|
|
|
image_holder_->setPixmap(*image_);
|
|
|
list_bounding_box_.clear();
|
|
|
list_polygon_.clear();
|
|
@@ -1562,7 +1583,7 @@ ImageLabeler::loadImages()
|
|
|
/* NOTREACHED */
|
|
|
}
|
|
|
|
|
|
- clearAll();
|
|
|
+ clearAllTool();
|
|
|
|
|
|
getImagesFromDir(QDir(dirName));
|
|
|
|
|
@@ -1574,7 +1595,8 @@ ImageLabeler::loadImages()
|
|
|
|
|
|
current_image_ = list_images_->begin();
|
|
|
|
|
|
- image_->load(list_images_->first());
|
|
|
+ image_->load(*current_image_);
|
|
|
+ image_holder_->resize(image_->size());
|
|
|
image_holder_->setPixmap(*image_);
|
|
|
|
|
|
enableTools();
|
|
@@ -1945,7 +1967,7 @@ ImageLabeler::BBoxFromString(
|
|
|
/* getting bbox id in the list(it cannot be changed) */
|
|
|
bool ok = 0;
|
|
|
int bboxID = getNumFromString(aString, "BBox #", ";", &ok);
|
|
|
- if (!ok || -1 <= bboxID) {
|
|
|
+ if (!ok || bboxID <= -1) {
|
|
|
qDebug() <<
|
|
|
"BBoxFromString: poly ID is corrupted";
|
|
|
return bbox;
|
|
@@ -1954,7 +1976,7 @@ ImageLabeler::BBoxFromString(
|
|
|
|
|
|
/* getting new label id */
|
|
|
int labelID = getNumFromString(aString, "LabelID: ", ";", &ok);
|
|
|
- if (!ok || -1 <= labelID) {
|
|
|
+ if (!ok || labelID <= -1) {
|
|
|
showWarning(
|
|
|
tr("new LabelID is wrong, area can not be changed")
|
|
|
);
|
|
@@ -2074,7 +2096,7 @@ ImageLabeler::polyFromString(
|
|
|
/* getting poly id in the list(it cannot be changed) */
|
|
|
bool ok = 0;
|
|
|
int polyID = getNumFromString(aString, "Poly #", ";", &ok);
|
|
|
- if (!ok || -1 <= polyID) {
|
|
|
+ if (!ok || polyID <= -1) {
|
|
|
qDebug() <<
|
|
|
"polyFromString: poly ID is corrupted";
|
|
|
return poly;
|
|
@@ -2083,7 +2105,7 @@ ImageLabeler::polyFromString(
|
|
|
|
|
|
/* getting new label id */
|
|
|
int labelID = getNumFromString(aString, "LabelID: ", ";", &ok);
|
|
|
- if (!ok || -1 <= labelID) {
|
|
|
+ if (!ok || labelID <= -1) {
|
|
|
showWarning(
|
|
|
tr("new LabelID is wrong, area can not be changed")
|
|
|
);
|
|
@@ -2484,11 +2506,11 @@ ImageLabeler::wheelEvent(QWheelEvent *anEvent)
|
|
|
{
|
|
|
/* zoomin */
|
|
|
if (0 < anEvent->delta()) {
|
|
|
- //image_holder_->scaleImage(ZoomIn, 1.1);
|
|
|
+ image_holder_->scaleImage(ZoomIn, 1.1);
|
|
|
}
|
|
|
/* zoomout */
|
|
|
else if (anEvent->delta() < 0) {
|
|
|
- //image_holder_->scaleImage(ZoomOut, 1.1);
|
|
|
+ image_holder_->scaleImage(ZoomOut, 1.1);
|
|
|
}
|
|
|
}
|
|
|
|