Эх сурвалжийг харах

-fixed bug with wrong bbox format in the list
-fixed bug with corrupted bbox editing by changing it's data in the list
-added "load image" action in the menu

gapchich 13 жил өмнө
parent
commit
c8f0c5bafa
3 өөрчлөгдсөн 92 нэмэгдсэн , 35 устгасан
  1. 9 18
      ImageHolder.cpp
  2. 81 16
      ImageLabeler.cpp
  3. 2 1
      ImageLabeler.h

+ 9 - 18
ImageHolder.cpp

@@ -88,17 +88,6 @@ ImageHolder::paintEvent(QPaintEvent *anEvent)
 			}
 			painter.drawPolygon(poly);
 		}
-//		switch(tool_) {
-//		case BoundingBoxTool:
-//			painter.drawRect();
-//			break;
-//		case PolygonTool:
-//			painter.drawPolygon(polygon_.poly);
-//			break;
-//		default:
-//			break;
-//		}
-
 	}
 
 	/* drawing bounding boxes */
@@ -119,10 +108,11 @@ ImageHolder::drawBoundingBoxes(
 		/* NOTREACHED */
 	}
 
-	Qt::PenStyle penStyle = Qt::SolidLine;
-	int width = 1;
+	Qt::PenStyle penStyle;
+	int width = 2;
 	/* confirmed boxes */
 	for (int i = 0; i < list_bounding_box_->size(); i++) {
+		penStyle = Qt::SolidLine;
 		int labelID = list_bounding_box_->at(i)->label_ID_;
 
 		if (labelID < list_label_color_->count())
@@ -134,12 +124,12 @@ ImageHolder::drawBoundingBoxes(
 		if (labelID == *main_label_)
 			width = 3;
 		else
-			width = 1;
+			width = 2;
 
 		if (RectFigure == focused_selection_type_ &&
 			focused_selection_ == i) {
 			penStyle = Qt::DotLine;
-			width = 2;
+			width = 3;
 		}
 
 		/* scaling */
@@ -223,7 +213,7 @@ ImageHolder::drawPolygons(
 	}
 
 	Qt::PenStyle penStyle = Qt::SolidLine;
-	int width = 1;
+	int width = 2;
 	/* confirmed polygons */
 	for (int i = 0; i < list_polygon_->size(); i++) {
 		penStyle = Qt::SolidLine;
@@ -238,12 +228,12 @@ ImageHolder::drawPolygons(
 		if (labelID == *main_label_)
 			width = 3;
 		else
-			width = 1;
+			width = 2;
 
 		if (PolyFigure == focused_selection_type_ &&
 			focused_selection_ == i) {
 			penStyle = Qt::DotLine;
-			width = 2;
+			width = 3;
 		}
 
 		QPoint point;
@@ -537,6 +527,7 @@ ImageHolder::confirmSelection()
 
 	if (BoundingBoxTool == tool_) {
 		BoundingBox *bbox = new BoundingBox;
+		bounding_box_.rect = bounding_box_.rect.normalized();
 		*bbox = bounding_box_;
 		list_bounding_box_->append(bbox);
 		bounding_box_.rect.setRect(-1, -1, 0, 0);

+ 81 - 16
ImageLabeler.cpp

@@ -70,12 +70,14 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 	menu_help_->setTitle(tr("&Help"));
 
 	/* menu file */
+	action_open_image_ = new QAction(this);
+	action_open_image_->setText(tr("&Load image"));
 	action_open_images_ = new QAction(this);
-	action_open_images_->setText(tr("&Load images"));
+	action_open_images_->setText(tr("&Load images(recursively)"));
 	action_open_labeled_image_ = new QAction(this);
-	action_open_labeled_image_->setText(tr("&Open labeled image"));
+	action_open_labeled_image_->setText(tr("&Load labeled image"));
 	action_load_legend_ = new QAction(this);
-	action_load_legend_->setText(tr("Load &legend"));
+	action_load_legend_->setText(tr("&Load legend"));
 	action_save_labels_ = new QAction(this);
 	action_save_labels_->setText(tr("&Save all info"));
 	action_save_labels_->setEnabled(false);
@@ -124,6 +126,7 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 	action_about_->setEnabled(false);
 	/* ------------------ */
 
+	menu_file_->addAction(action_open_image_);
 	menu_file_->addAction(action_open_images_);
 	menu_file_->addAction(action_open_labeled_image_);
 	menu_file_->addAction(action_load_legend_);
@@ -361,6 +364,12 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 		this,
 		SLOT(loadImages())
 		);
+	connect(
+		action_open_image_,
+		SIGNAL(triggered()),
+		this,
+		SLOT(loadImage())
+		);
 	connect(
 		action_open_labeled_image_,
 		SIGNAL(triggered()),
@@ -595,6 +604,7 @@ ImageLabeler::~ImageLabeler()
 {
 	delete action_quit_;
 	delete action_open_labeled_image_;
+	delete action_open_image_;
 	delete action_open_images_;
 	delete action_load_legend_;
 	delete action_save_legend_;
@@ -848,11 +858,11 @@ ImageLabeler::addBBoxArea(
 	label.append(QString("BBox #%1; ").arg(anID));
 	label.append(QString("LabelID: %1; ").arg(aBBox.label_ID_));
 	label.append(
-		QString("points:%1;%2;%3;%4; ").
+		QString("data:%1;%2;%3;%4; ").
 		arg(aBBox.rect.topLeft().x()).
 		arg(aBBox.rect.topLeft().y()).
-		arg(aBBox.rect.bottomRight().x()).
-		arg(aBBox.rect.bottomRight().y())
+		arg(aBBox.rect.width()).
+		arg(aBBox.rect.height())
 		);
 
 	newItem->setText(label);
@@ -1436,12 +1446,15 @@ ImageLabeler::saveLegend()
 		fileDialog.setAcceptMode(QFileDialog::AcceptSave);
 		fileDialog.setDefaultSuffix("dat");
 		fileDialog.setFileMode(QFileDialog::AnyFile);
+		QString dir = getDirFromPath(&(*current_image_));
 
 		/* altering the name of a new file */
 		QString newFileName = alterFileName(*current_image_, "_legend");
 
 		fileDialog.selectFile(newFileName);
 
+		fileDialog.setDirectory(dir);
+
 		QString filename;
 		if (fileDialog.exec()) {
 			filename = fileDialog.selectedFiles().last();
@@ -1583,7 +1596,7 @@ ImageLabeler::loadInfo()
 
 					if (!ok) {
 						qDebug() <<
-							"while getting poly: "
+							"loadInfo: "
 							"poly id format is corrupted";
 						subNode = subNode.nextSibling();
 						continue;
@@ -1606,6 +1619,57 @@ ImageLabeler::loadInfo()
 	}
 }
 
+void
+ImageLabeler::loadImage()
+{
+	if (askForUnsavedData()) {
+		return;
+		/* NOTREACHED */
+	}
+
+	QFileDialog fileDialog(0, tr("Load image"));
+	fileDialog.setFileMode(QFileDialog::AnyFile);
+	QString filename;
+
+	if (fileDialog.exec()) {
+		filename = fileDialog.selectedFiles().last();
+	}
+	else {
+		//showWarning(tr("Could not open file dialog"));
+		return;
+		/* NOTREACHED */
+	}
+
+	if (filename.isEmpty()) {
+		return;
+		/* NOTREACHED */
+	}
+
+	clearAllTool();
+
+
+	list_images_->append(filename);
+
+	if (list_images_->isEmpty()) {
+		return;
+		/* NOTREACHED */
+	}
+
+	current_image_ = list_images_->end();
+	current_image_--;
+
+	QString winTitle;
+	winTitle.append("ImageLabeler - ");
+	winTitle.append(*current_image_);
+	setWindowTitle(winTitle);
+
+	image_->load(*current_image_);
+	image_holder_->resize(image_->size());
+	image_holder_->setPixmap(*image_);
+
+	enableTools();
+}
+
 void
 ImageLabeler::loadImages()
 {
@@ -1756,7 +1820,7 @@ ImageLabeler::loadLegendFromNode(QDomElement *anElement)
 
 			if (!ok) {
 				qDebug() <<
-					"while getting legend: "
+					"loadLegendFromNode: "
 					"label id format is corrupted";
 				subNode = subNode.nextSibling();
 				continue;
@@ -1767,7 +1831,7 @@ ImageLabeler::loadLegendFromNode(QDomElement *anElement)
 
 			if (!ok) {
 				qDebug() <<
-					"while getting legend: "
+					"loadLegendFromNode: "
 					"label isMain flag format is corrupted";
 				subNode = subNode.nextSibling();
 				continue;
@@ -1778,7 +1842,7 @@ ImageLabeler::loadLegendFromNode(QDomElement *anElement)
 
 			if (!ok) {
 				qDebug() <<
-					"while getting legend: "
+					"loadLegendFromNode: "
 					"label color format is corrupted";
 				subNode = subNode.nextSibling();
 				continue;
@@ -1972,6 +2036,7 @@ ImageLabeler::BBoxFromData(
 	QString *aBBoxData
 )
 {
+	qDebug() << *aBBoxData;
 	BoundingBox bbox;
 	QString buffer;
 	bbox.rect.setRect(-1, -1, -1, -1);
@@ -1987,8 +2052,8 @@ ImageLabeler::BBoxFromData(
 		int bboxData = buffer.toInt(&ok, 10);
 		if (!ok) {
 			qDebug() <<
-				"while getting objects: "
-				"poly format is corrupted";
+				"BBoxFromData: "
+				"bbox format is corrupted";
 			break;
 		}
 
@@ -2048,7 +2113,7 @@ ImageLabeler::BBoxFromString(
 	int bboxID = getNumFromString(aString, "BBox #", ";", &ok);
 	if (!ok || bboxID <= -1) {
 		qDebug() <<
-			"BBoxFromString: poly ID is corrupted";
+			"BBoxFromString: bboxID is corrupted";
 		return bbox;
 		/* NOTREACHED */
 	}
@@ -2064,11 +2129,11 @@ ImageLabeler::BBoxFromString(
 	}
 
 	/* getting new points */
-	int pointsPos = aString->indexOf("points:") + 7;
+	int pointsPos = aString->indexOf("data:") + 5;
 	int pointsLen = aString->size() - pointsPos;
 	if (pointsLen <= 0) {
 		showWarning(
-			tr("new points data is wrong, area can not be changed")
+			tr("new data is wrong, area can not be changed")
 				);
 		return bbox;
 		/* NOTREACHED */
@@ -2123,7 +2188,7 @@ ImageLabeler::polyFromData(
 		int polyCoor = buffer.toInt(&ok, 10);
 		if (!ok) {
 			qDebug() <<
-				"while getting objects: "
+				"polyFromData: "
 				"poly format is corrupted";
 			break;
 		}

+ 2 - 1
ImageLabeler.h

@@ -100,13 +100,14 @@ public slots:
 	void deleteArea();
 	void editArea();
 	void toggleLabelPriority();
-	void loadImages();
 	void nextImage();
 	void prevImage();
 	void editLabel(QListWidgetItem *anItem);
 	void saveAllInfo();
 	void saveSegmentedPicture();
 	void saveLegend();
+	void loadImage();
+	void loadImages();
 	void loadInfo();
 	void loadLegendFromFile();
 	void setBoundingBoxTool(bool aButtonPressed);