|
|
@@ -10,12 +10,20 @@
|
|
|
#include <QGraphicsSimpleTextItem>
|
|
|
#include <QPixmap>
|
|
|
#include <QImage>
|
|
|
+#include <QMenu>
|
|
|
+#include <QFileDialog>
|
|
|
|
|
|
AnnotatedImageView::AnnotatedImageView(QWidget* parent) : QGraphicsView(parent)
|
|
|
{
|
|
|
scene_ = new QGraphicsScene(this);
|
|
|
setScene(scene_);
|
|
|
rect_ = QRectF(0, 0, 0, 0);
|
|
|
+
|
|
|
+ actionExportImage = new QAction(tr("Export Annotated Image..."), this);
|
|
|
+ actionExportImage->setEnabled(false);
|
|
|
+ connect(actionExportImage, &QAction::triggered, this, &AnnotatedImageView::exportImage);
|
|
|
+
|
|
|
+ setRenderHint(QPainter::Antialiasing);
|
|
|
}
|
|
|
|
|
|
void AnnotatedImageView::ClearImage() {
|
|
|
@@ -25,6 +33,7 @@ void AnnotatedImageView::ClearImage() {
|
|
|
image_ = nullptr;
|
|
|
}
|
|
|
rect_ = QRectF(0, 0, 0, 0);
|
|
|
+ actionExportImage->setEnabled(false);
|
|
|
}
|
|
|
|
|
|
void AnnotatedImageView::DisplayImage(std::string filename, std::vector<Conv::BoundingBox> bounding_boxes, Conv::ClassManager *class_manager) {
|
|
|
@@ -62,30 +71,46 @@ void AnnotatedImageView::DisplayImage(std::string filename, std::vector<Conv::Bo
|
|
|
|
|
|
// Klassenbezeichnung ausgeben
|
|
|
QString class_name = QString::fromStdString(class_manager->GetClassInfoById(box.c).first);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
auto* text_item = new QGraphicsSimpleTextItem(class_name);
|
|
|
if(image_->width() >= 800) {
|
|
|
text_item->setFont(QFont(tr("Helvetica"), 24));
|
|
|
} else {
|
|
|
- text_item->setFont(QFont(tr("Helvetica"), 16));
|
|
|
+ text_item->setFont(QFont(tr("Helvetica"), 32));
|
|
|
}
|
|
|
- text_item->setPos(box.x, box.y + box.h);
|
|
|
+ text_item->setPos(box.x + 10, box.y - 3);// + box.h);
|
|
|
qreal text_width = text_item->boundingRect().width();
|
|
|
qreal text_height = text_item->boundingRect().height();
|
|
|
- if(box.y + box.h + text_height > y2) y2 = box.y + box.h + text_height;
|
|
|
+ text_item->setPos(box.x + 10, box.y - text_height - 3);// + box.h);
|
|
|
+ // if(box.y + box.h + text_height > y2) y2 = box.y + box.h + text_height;
|
|
|
+
|
|
|
+ QColor class_background = QColor::fromRgbF(1,1,1,0.9);
|
|
|
+ QColor box_background = QColor::fromRgbF(1,1,1,0.2);
|
|
|
+ QColor box_border = QColor::fromRgbF(0,0,0,1);
|
|
|
+
|
|
|
+ if(box.c == UNKNOWN_CLASS) {
|
|
|
+ class_background = QColor::fromRgbF(1,0.5,0.5,0.5);
|
|
|
+ box_background = QColor::fromRgbF(1,0.5,0.5,0.1);
|
|
|
+ box_border = QColor::fromRgbF(0.5,0,0,0.5);
|
|
|
+ }
|
|
|
|
|
|
// Hintergrund der Klassenbezeichnung
|
|
|
- scene_->addRect(box.x, box.y + box.h, text_width, text_height, QPen(), QBrush(QColor::fromRgbF(1,1,1,0.9)));
|
|
|
+ scene_->addRect(box.x, box.y - text_height, text_width + 20, text_height, QPen(), QBrush(QColor::fromRgbF(1,1,1,0.9)));
|
|
|
scene_->addItem(text_item);
|
|
|
|
|
|
// Bounding Box zeichnen
|
|
|
- scene_->addRect(box.x, box.y, box.w, box.h,QPen(QBrush(QColor::fromRgbF(0,0,0,1)), 3.0), QBrush(QColor::fromRgbF(1,1,1,0.2)));
|
|
|
-
|
|
|
+ scene_->addRect(box.x, box.y, box.w, box.h,QPen(QBrush(box_border), 3.0), QBrush(box_background));
|
|
|
}
|
|
|
|
|
|
- if(image_->width() >= 800) {
|
|
|
+ const qreal border = 85;
|
|
|
+ QRectF bounding_rect(x1 - border, y1 - border, (2.0 * border) + x2 - x1, (2.0 * border) + y2 - y1);
|
|
|
+ QRectF noborder_rect(x1, y1, x2 - x1, y2 - y1);
|
|
|
+ scene_->setSceneRect(noborder_rect);
|
|
|
+
|
|
|
+ if(width >= 800) {
|
|
|
// Großes Bild, Umgebungsrechteck für passende Anzeige feststellen
|
|
|
- const qreal border = 85;
|
|
|
- QRectF bounding_rect(x1 - border, y1 - border, (2.0 * border) + x2 - x1, (2.0 * border) + y2 - y1);
|
|
|
rect_ = bounding_rect;
|
|
|
RefitDisplay();
|
|
|
} else {
|
|
|
@@ -93,6 +118,7 @@ void AnnotatedImageView::DisplayImage(std::string filename, std::vector<Conv::Bo
|
|
|
rect_ = QRectF(0, 0, 0, 0);
|
|
|
RefitDisplay();
|
|
|
}
|
|
|
+ actionExportImage->setEnabled(true);
|
|
|
}
|
|
|
|
|
|
void AnnotatedImageView::RefitDisplay() {
|
|
|
@@ -102,3 +128,26 @@ void AnnotatedImageView::RefitDisplay() {
|
|
|
this->fitInView(rect_, Qt::KeepAspectRatio);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+void AnnotatedImageView::contextMenuEvent(QContextMenuEvent *event) {
|
|
|
+ QMenu menu(this);
|
|
|
+ menu.addAction(actionExportImage);
|
|
|
+ menu.exec(event->globalPos());
|
|
|
+}
|
|
|
+
|
|
|
+void AnnotatedImageView::exportImage() {
|
|
|
+ // Calculate image bounds
|
|
|
+ auto rect = scene_->sceneRect();
|
|
|
+ QImage image(rect.width(), rect.height(), QImage::Format_RGBA8888);
|
|
|
+
|
|
|
+ // Render image
|
|
|
+ QPainter painter(&image);
|
|
|
+ painter.setRenderHint(QPainter::Antialiasing);
|
|
|
+ scene_->render(&painter);
|
|
|
+
|
|
|
+ // Get file name
|
|
|
+ QString fileName = QFileDialog::getSaveFileName(this, tr("Export Annotated Image"), QString(), tr("Image (*.jpg *.jpeg *.png)"));
|
|
|
+
|
|
|
+ if(fileName.length() > 0)
|
|
|
+ image.save(fileName);
|
|
|
+}
|