瀏覽代碼

-added PASCAL format reading

gapchich 13 年之前
父節點
當前提交
28d8954c12
共有 8 個文件被更改,包括 705 次插入71 次删除
  1. 622 42
      ImageLabeler.cpp
  2. 25 6
      ImageLabeler.h
  3. 4 8
      Makefile
  4. 6 5
      Makefile.Debug
  5. 8 7
      Makefile.Release
  6. 22 2
      functions.cpp
  7. 14 1
      functions.h
  8. 4 0
      main.cpp

+ 622 - 42
ImageLabeler.cpp

@@ -40,7 +40,7 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 	 * Variables
 	 */
 
-	list_images_ = new QStringList();
+	list_images_ = new QList< Image >;
 
 	main_label_ = -1;
 	pure_data_ = 0;
@@ -62,6 +62,8 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 
 	menu_file_ = new QMenu(menu_bar_);
 	menu_file_->setTitle(tr("&File"));
+	menu_pascal_ = new QMenu(menu_bar_);
+	menu_pascal_->setTitle(tr("&Pascal"));
 	menu_view_ = new QMenu(menu_bar_);
 	menu_view_->setTitle(tr("&View"));
 	menu_edit_ = new QMenu(menu_bar_);
@@ -89,6 +91,11 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 	action_save_legend_->setEnabled(false);
 	action_quit_ = new QAction(this);
 	action_quit_->setText(tr("&Quit"));
+	/* menu pascal */
+	action_load_pascal_file_ = new QAction(this);
+	action_load_pascal_file_->setText(tr("&Load pascal file"));
+	action_load_pascal_poly_ = new QAction(this);
+	action_load_pascal_poly_->setText(tr("&Load poly info"));
 	/* menu view */
 	action_view_normal_ = new QAction(this);
 	action_view_normal_->setText(tr("&Normal"));
@@ -130,19 +137,27 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 	menu_file_->addAction(action_open_images_);
 	menu_file_->addAction(action_open_labeled_image_);
 	menu_file_->addAction(action_load_legend_);
+	menu_file_->addAction(menu_pascal_->menuAction());
+	menu_file_->addSeparator();
 	menu_file_->addAction(action_save_segmented_);
 	menu_file_->addAction(action_save_legend_);
 	menu_file_->addAction(action_save_labels_);
+	menu_file_->addSeparator();
 	menu_file_->addAction(action_quit_);
 
+	menu_pascal_->addAction(action_load_pascal_file_);
+	menu_pascal_->addAction(action_load_pascal_poly_);
+
 	menu_view_->addAction(action_view_normal_);
 	menu_view_->addAction(action_view_segmented_);
 
 	menu_edit_->addAction(action_undo_);
 	menu_edit_->addAction(action_redo_);
+	menu_edit_->addSeparator();
 	menu_edit_->addAction(action_bound_box_tool_);
 	menu_edit_->addAction(action_polygon_tool_);
 	menu_edit_->addAction(action_tagging_tool_);
+	menu_edit_->addSeparator();
 	menu_edit_->addAction(action_add_description_);
 	menu_edit_->addAction(action_options_);
 
@@ -207,7 +222,7 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 	frame_image_->setMidLineWidth(0);
 	frame_image_->setWidgetResizable(false);
 	frame_image_->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
-	frame_image_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
+	frame_image_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
 	frame_labelbox_ = new QFrame(central_widget_);
 	frame_labelbox_->setFrameStyle(QFrame::StyledPanel | QFrame::Raised);
 	frame_labelbox_->setLineWidth(0);
@@ -222,8 +237,6 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 	//image_holder_->setStyleSheet("QLabel {background: #ffffff;}");
 	image_holder_->setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
 	image_holder_->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
-	image_holder_->setFocusPolicy(Qt::StrongFocus);
-	image_holder_->setFocus();
 	image_holder_->setScaledContents(true);
 	image_holder_->setFrameStyle(QFrame::Box | QFrame::Plain);
 	image_holder_->setLineWidth(0);
@@ -396,6 +409,18 @@ ImageLabeler::ImageLabeler(QWidget *aParent) :
 		this,
 		SLOT(loadLegendFromFile())
 		);
+	connect(
+		action_load_pascal_file_,
+		SIGNAL(triggered()),
+		this,
+		SLOT(loadPascalFile())
+		);
+	connect(
+		action_load_pascal_poly_,
+		SIGNAL(triggered()),
+		this,
+		SLOT(loadPascalPolys())
+		);
 	connect(
 		action_save_legend_,
 		SIGNAL(triggered()),
@@ -639,6 +664,8 @@ ImageLabeler::~ImageLabeler()
 	delete action_open_image_;
 	delete action_open_images_;
 	delete action_load_legend_;
+	delete action_load_pascal_file_;
+	delete action_load_pascal_poly_;
 	delete action_save_legend_;
 	delete action_save_segmented_;
 	delete action_save_labels_;
@@ -654,6 +681,7 @@ ImageLabeler::~ImageLabeler()
 	delete action_about_;
 	delete action_help_content_;
 
+	delete menu_pascal_;
 	delete menu_file_;
 	delete menu_view_;
 	delete menu_edit_;
@@ -726,13 +754,17 @@ ImageLabeler::~ImageLabeler()
 }
 
 void
-ImageLabeler::addImage(QString *anImage)
+ImageLabeler::addImage(Image *anImage)
 {
 	QListWidgetItem *newItem = new QListWidgetItem;
 
 	QString itemText = QString("%1: %2").
 		arg(list_images_widget_->count()).
-		arg(getFilenameFromPath(anImage));
+		arg(getFilenameFromPath(&(anImage->image_)));
+	if (anImage->labeled_)
+		itemText.append(" #labeled");
+	if (anImage->pas_)
+		itemText.append(" #pas");
 	newItem->setText(itemText);
 
 	list_images_widget_->addItem(newItem);
@@ -1190,17 +1222,38 @@ ImageLabeler::getImagesFromDir(const QDir &dir)
 		"*.gif" <<
 		"*.png" <<
 		"*.bmp" <<
-		"*.tiff"
+		"*.tiff" <<
+		"*.dat"
 		;
 
 	QStringList listImages =
 		dir.entryList(filenameFilter, QDir::Files);
+	QStringList ignoredFiles;
 
 	foreach (QString file, listImages) {
-		QString itemText = dir.absoluteFilePath(file);
-		addImage(&itemText);
-		//list_label_->setItemSelected(newItem, true);
-		//list_images_->append(dir.absoluteFilePath(file));
+		qDebug() << "file is: " << file;
+		if (ignoredFiles.contains(file) ||
+			file.contains("_segmented", Qt::CaseInsensitive) ||
+			file.contains(".dat", Qt::CaseInsensitive)) {
+			continue;
+		}
+
+		Image newImage;
+		newImage.image_ = dir.absoluteFilePath(file);
+		/* TODO: think about loading pascal files */
+		newImage.pas_ = 0;
+
+		QString labeled = alterFileName(file, "_labeled");
+		labeled = removePath(labeled);
+		labeled.append(".dat");
+		if (listImages.contains(labeled, Qt::CaseInsensitive))
+			newImage.labeled_ = 1;
+		else
+		{
+			newImage.labeled_ = 0;
+		}
+
+		addImage(&newImage);
 	}
 
 	QStringList listDir = dir.entryList(QDir::Dirs);
@@ -1225,12 +1278,18 @@ ImageLabeler::nextImage()
 	}
 
 	if (list_images_widget_->count() - 1 == image_ID_) {
-		current_image_ = list_images_->at(0);
+		//current_image_ = list_images_->at(0).image_;
 		image_ID_ = 0;
 	}
 	else {
 		image_ID_ ++;
-		current_image_ = list_images_->at(image_ID_);
+		//current_image_ = list_images_->at(image_ID_).image_;
+	}
+
+	if (!selectImage(image_ID_)) {
+		showWarning(tr("Next image is not available"));
+		return;
+		/* NOTREACHED */
 	}
 
 	list_images_widget_->setCurrentRow(image_ID_);
@@ -1252,6 +1311,8 @@ ImageLabeler::nextImage()
 	list_polygon_.clear();
 	list_areas_->clear();
 	image_holder_->clearAll();
+	segmented_image_.clear();
+	clearLabelColorList();
 
 	//setWindowTitle(tr("ImageLabeler"));
 }
@@ -1271,15 +1332,21 @@ ImageLabeler::prevImage()
 
 	if (!image_ID_) {
 		image_ID_ = list_images_widget_->count() - 1;
-		current_image_ = list_images_->at(image_ID_);
+		//current_image_ = list_images_->at(image_ID_).image_;
 	}
 	else {
 		image_ID_--;
-		current_image_ = list_images_->at(image_ID_);
+		//current_image_ = list_images_->at(image_ID_).image_;
 	}
 
 	list_images_widget_->setCurrentRow(image_ID_);
 
+	if (!selectImage(image_ID_)) {
+		showWarning(tr("Next image is not available"));
+		return;
+		/* NOTREACHED */
+	}
+
 	QString winTitle;
 	winTitle.append("ImageLabeler - ");
 	winTitle.append(current_image_);
@@ -1292,6 +1359,8 @@ ImageLabeler::prevImage()
 	list_polygon_.clear();
 	list_areas_->clear();
 	image_holder_->clearAll();
+	segmented_image_.clear();
+	clearLabelColorList();
 
 	//setWindowTitle(tr("ImageLabeler"));
 }
@@ -1366,6 +1435,7 @@ ImageLabeler::saveAllInfo()
 
 	/* altering the name of a new file */
 	QString newFileName = alterFileName(current_image_, "_labeled");
+	newFileName = removePath(newFileName);
 
 	fileDialog.selectFile(newFileName);
 
@@ -1421,6 +1491,7 @@ ImageLabeler::saveSegmentedPicture()
 
 	/* altering the name of a new file */
 	QString newFileName = alterFileName(current_image_, "_segmented");
+	newFileName = removePath(newFileName);
 
 	fileDialog.selectFile(newFileName);
 
@@ -1519,6 +1590,7 @@ ImageLabeler::saveLegend()
 
 		/* altering the name of a new file */
 		QString newFileName = alterFileName(current_image_, "_legend");
+		newFileName = removePath(newFileName);
 
 		fileDialog.selectFile(newFileName);
 
@@ -1573,11 +1645,30 @@ ImageLabeler::loadInfo()
 		/* NOTREACHED */
 	}
 
+	clearAllTool();
+	clearLabelList();
+	if (loadInfo(filename)) {
+		enableTools();
+		Image newImage;
+		newImage.image_ = current_image_;
+		newImage.labeled_ = 1;
+		newImage.pas_ = 0;
+		addImage(&newImage);
+		image_ID_ = list_images_widget_->count() - 1;
+		list_images_widget_->setCurrentRow(image_ID_);
+	}
+
+	unsaved_data_ = 0;
+}
+
+bool
+ImageLabeler::loadInfo(QString filename)
+{
 	QDomDocument doc("Image Labeler");
 	QFile file(filename);
 	if (!file.open(QIODevice::ReadOnly)) {
 		showWarning(tr("Can not open such file"));
-		return;
+		return false;
 		/* NOTREACHED */
 	}
 
@@ -1585,15 +1676,14 @@ ImageLabeler::loadInfo()
 	if (!doc.setContent(&file, &errMsg)) {
 		showWarning(errMsg);
 		file.close();
-		return;
+		return false;
 		/* NOTREACHED */
 	}
 
 	file.close();
 
-	clearAll();
-	list_label_->clear();
-	enableTools();
+	//clearAll();
+	//enableTools();
 
 	/* getting all info */
 	QDomElement elements = doc.documentElement();
@@ -1612,17 +1702,20 @@ ImageLabeler::loadInfo()
 						"The file with data doesn't contain path to the image"
 						)
 						);
-					return;
+					return false;
 					/* NOTREACHED */
 				}
 				if (!image_->load(string)) {
-					return;
+					return false;
 					/* NOTREACHED */
 				}
-				addImage(&string);
+//				Image newImage;
+//				newImage.image_ = string;
+//				newImage.labeled_ = 1;
+//				addImage(&newImage);
 				current_image_ = string;
-				image_ID_ = list_images_widget_->count() - 1;
-				list_images_widget_->setCurrentRow(image_ID_);
+//				image_ID_ = list_images_widget_->count() - 1;
+//				list_images_widget_->setCurrentRow(image_ID_);
 
 				QString winTitle;
 				winTitle.append("ImageLabeler - ");
@@ -1679,10 +1772,10 @@ ImageLabeler::loadInfo()
 					string = subElement.text();
 
 					if (subElement.tagName() == "bbox") {
-						setBBoxFromData(&string, &id);
+						addBBoxFromData(&string, &id);
 					}
 					if (subElement.tagName() == "poly") {
-						setPolyFromData(&string, &id);
+						addPolyFromData(&string, &id);
 					}
 
 					subNode = subNode.nextSibling();
@@ -1691,6 +1784,371 @@ ImageLabeler::loadInfo()
 		}
 		rootNode = rootNode.nextSibling();
 	}
+
+	unsaved_data_ = 0;
+	return true;
+}
+
+void
+ImageLabeler::loadPascalFile()
+{
+	if (askForUnsavedData()) {
+		return;
+		/* NOTREACHED */
+	}
+
+	QFileDialog fileDialog(0, tr("Load pascal file"));
+	fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
+	fileDialog.setDefaultSuffix("xml");
+	fileDialog.setFileMode(QFileDialog::AnyFile);
+	QStringList filters;
+	filters << "PASCAL xml data (*.xml)"
+			<< "Any files (*)";
+
+	fileDialog.setNameFilters(filters);
+
+	QString filename;
+	if (fileDialog.exec()) {
+		filename = fileDialog.selectedFiles().last();
+	}
+	else {
+		//showWarning(tr("Can not open file dialog"));
+		return;
+		/* NOTREACHED */
+	}
+
+	clearAllTool();
+	clearLabelList();
+	if (loadPascalFile(filename)) {
+		qDebug() << list_bounding_box_.at(0)->label_ID_;
+		qDebug() << list_bounding_box_.size();
+		enableTools();
+		Image newImage;
+		newImage.image_ = current_image_;
+		newImage.labeled_ = 1;
+		newImage.pas_ = 1;
+		addImage(&newImage);
+		image_ID_ = list_images_widget_->count() - 1;
+		list_images_widget_->setCurrentRow(image_ID_);
+	}
+
+	unsaved_data_ = 0;
+}
+
+bool
+ImageLabeler::loadPascalFile(QString aFilename)
+{
+	QDomDocument doc;
+	QFile file(aFilename);
+	if (!file.open(QIODevice::ReadOnly)) {
+		showWarning(tr("Can not open such file"));
+		return false;
+		/* NOTREACHED */
+	}
+
+	QString errMsg;
+	if (!doc.setContent(&file, &errMsg)) {
+		showWarning(errMsg);
+		file.close();
+		return false;
+		/* NOTREACHED */
+	}
+
+	file.close();
+
+	//clearAll();
+	//enableTools();
+
+	/* getting all info */
+	QDomElement elements = doc.documentElement();
+	QDomNode rootNode = elements.firstChild();
+	QString string;
+	QString path = getPathFromFilename(aFilename);
+	qDebug() << path;
+	QString filename;
+	QStringList labels;
+	labels << "BACKGROUND";
+	int labelID;
+
+	while(!rootNode.isNull()) {
+		QDomElement element = rootNode.toElement();
+		if(!element.isNull()) {
+			/* folder */
+			if (element.tagName() == "folder") {
+				string = element.text();
+				if (!string.isEmpty()) {
+					path.append(string);
+				}
+			}
+			/* filename */
+			else if (element.tagName() == "filename") {
+				string = element.text();
+				if (!string.isEmpty()) {
+					filename = string;
+				}
+			}
+			/* object */
+			else if (element.tagName() == "object") {
+				QDomNode subNode = element.firstChild();
+				QDomElement subElement;
+
+				while(!subNode.isNull()) {
+					subElement = subNode.toElement();
+
+					if (subElement.isNull() || subElement.text().isEmpty()) {
+						subNode = subNode.nextSibling();
+						continue;
+					}
+
+					/* label */
+					if (subElement.tagName() == "name") {
+						string = subElement.text();
+						if (!string.isEmpty() &&
+							!labels.contains(string, Qt::CaseInsensitive))
+						{
+							addLabel(list_label_->count(), 0, string);
+							labelID = labels.count();
+							labels << string;
+						}
+						else if (labels.contains(string, Qt::CaseInsensitive)) {
+							for (int i = 0; i < labels.count(); i++) {
+								if (labels.at(i) == string)
+									labelID = i;
+							}
+
+						}
+					}
+
+					if (subElement.tagName() == "bndbox") {
+						/* 2 points */
+						QPoint topLeft;
+						QPoint bottomRight;
+						QDomNode bboxNode = subElement.firstChild();
+						QDomElement bboxElement;
+						while(!bboxNode.isNull()) {
+							bboxElement = bboxNode.toElement();
+							string.clear();
+							bool ok = 1;
+							if (bboxElement.tagName() == "xmin") {
+								string = bboxElement.text();
+								if (string.isEmpty())
+									ok = 0;
+								double xmin = string.toDouble(&ok);
+								if (ok)
+									topLeft.setX(qRound(xmin));
+
+							}
+							else if (bboxElement.tagName() == "ymin") {
+								string = bboxElement.text();
+								if (string.isEmpty())
+									ok = 0;
+								double ymin = string.toDouble(&ok);
+								if (ok)
+									topLeft.setY(qRound(ymin));
+							}
+							else if (bboxElement.tagName() == "xmax") {
+								string = bboxElement.text();
+								if (string.isEmpty())
+									ok = 0;
+								double xmax = string.toDouble(&ok);
+								if (ok)
+									bottomRight.setX(qRound(xmax));
+							}
+							else if (bboxElement.tagName() == "ymax") {
+								string = bboxElement.text();
+								if (string.isEmpty())
+									ok = 0;
+								double ymax = string.toDouble(&ok);
+								if (ok)
+									bottomRight.setY(qRound(ymax));
+							}
+							qDebug() << string;
+							if (string.isEmpty() || !ok)
+								break;
+
+							bboxNode = bboxNode.nextSibling();
+
+							if (bboxNode.isNull()) {
+								BoundingBox *bbox = new BoundingBox;
+								bbox->rect.setTopLeft(topLeft);
+								bbox->rect.setBottomRight(bottomRight);
+								bbox->label_ID_ = labelID;
+
+								addBBox(bbox);
+							}
+						}
+					}
+					subNode = subNode.nextSibling();
+				}
+			}
+		}
+
+		rootNode = rootNode.nextSibling();
+	}
+
+	qDebug() << path  + "/" + filename;
+	if (!image_->load(path + "/" + filename)) {
+		return false;
+		/* NOTREACHED */
+	}
+
+	current_image_ = path + filename;
+
+	QString winTitle;
+	winTitle.append("ImageLabeler - ");
+	winTitle.append(current_image_);
+	setWindowTitle(winTitle);
+
+	image_holder_->resize(image_->size());
+	image_holder_->setPixmap(*image_);
+
+	unsaved_data_ = 0;
+	return true;
+}
+
+void
+ImageLabeler::loadPascalPolys()
+{
+	if (current_image_.isEmpty()) {
+		return;
+		/* NOTREACHED */
+	}
+
+	QFileDialog fileDialog(0, tr("Load pascal polygons"));
+	fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
+	fileDialog.setDefaultSuffix("polygon");
+	fileDialog.setFileMode(QFileDialog::AnyFile);
+	QStringList filters;
+	filters << "PASCAL polygons (*.polygon)"
+			<< "Any files (*)";
+
+	fileDialog.setNameFilters(filters);
+
+	QString filename;
+	if (fileDialog.exec()) {
+		filename = fileDialog.selectedFiles().last();
+	}
+	else {
+		//showWarning(tr("Can not open file dialog"));
+		return;
+		/* NOTREACHED */
+	}
+
+	//clearAllTool();
+	//clearLabelList();
+	if (!loadPascalPolys(filename)) {
+		showWarning(tr("File format is corrupted."));
+	}
+
+	unsaved_data_ = 0;
+	image_holder_->update();
+}
+
+bool
+ImageLabeler::loadPascalPolys(QString aFilename)
+{
+	QFile file(aFilename);
+	if (!file.open(QIODevice::ReadOnly)) {
+		showWarning(tr("Can not open such file"));
+		return false;
+		/* NOTREACHED */
+	}
+
+	QByteArray data = file.readAll();
+
+	file.close();
+
+	QString label;
+	int lastSpace = 0;
+	int pointCount = 0;
+	Polygon *poly = 0;
+	QPoint point;
+	bool evenFlag = 0;
+	//for (int i = 0; i < data.length(); i++) {
+	int i = 0;
+	while (i < data.length()) {
+		qDebug() << data.at(i);
+		if (data.at(i) == ' ' && label.isEmpty() && !pointCount) {
+			label = QString(data.mid(lastSpace, i - lastSpace));
+			qDebug() << label;
+			lastSpace = i + 1;
+		}
+		else if (data.at(i) == ' ' && !label.isEmpty() && !pointCount) {
+			QString num = QString(data.mid(lastSpace, i - lastSpace));
+			qDebug() << num;
+			bool ok = 1;
+			pointCount = num.toInt(&ok, 10);
+			if (!ok) {
+				return false;
+				/* NOTREACHED */
+			}
+			poly = new Polygon;
+			poly->label_ID_ = -1;
+			lastSpace = i + 1;
+		}
+		else if (data.at(i) == ' ' &&
+			!label.isEmpty() &&
+			pointCount &&
+			!evenFlag)
+		{
+			evenFlag = 1;
+			QString num = QString(data.mid(lastSpace, i - lastSpace));
+			qDebug() << num;
+			bool ok = 1;
+			int coor = qRound(num.toDouble(&ok));
+			if (!ok) {
+				return false;
+				/* NOTREACHED */
+			}
+			point.setX(coor);
+			lastSpace = i + 1;
+		}
+		else if (data.at(i) == ' ' &&
+			!label.isEmpty() &&
+			pointCount &&
+			evenFlag)
+		{
+			evenFlag = 0;
+			pointCount--;
+			QString num = QString(data.mid(lastSpace, i - lastSpace));
+			qDebug() << num;
+			bool ok = 1;
+			int coor = qRound(num.toDouble(&ok));
+			if (!ok) {
+				return false;
+				/* NOTREACHED */
+			}
+			point.setY(coor);
+			lastSpace = i + 1;
+			poly->poly << point;
+		}
+		else if (data.at(i) == '\n') {
+			if (pointCount || !poly) {
+				return false;
+				/* NOTREACHED */
+			}
+			lastSpace = i + 1;
+			for (int j = 0; j < list_label_->count(); j++) {
+				if (list_label_->item(j)->text().contains(label, Qt::CaseInsensitive)) {
+					poly->label_ID_ = j;
+				}
+			}
+			if (-1 == poly->label_ID_) {
+				int labelID = list_label_->count();
+				addLabel(labelID, 0, label);
+				poly->label_ID_ = labelID;
+			}
+			addPoly(poly);
+			label.clear();
+		}
+
+		i++;
+	}
+
+	//clearAll();
+	//enableTools();
+
+	return true;
 }
 
 void
@@ -1724,8 +2182,21 @@ ImageLabeler::loadImage()
 		/* NOTREACHED */
 	}
 
-	clearAllTool();
+	QDir dir(filename);
+	QStringList filter;
+	filter << "*.dat";
+	QStringList fileList = dir.entryList(filter, QDir::Files);
+	QString labeled = alterFileName(filename, "_labeled");
+	labeled = removePath(labeled);
+	labeled.append(".dat");
+	if (fileList.contains(labeled, Qt::CaseInsensitive)) {
+		labeled = dir.absoluteFilePath(labeled);
+		loadInfo(labeled);
+		return;
+		/* NOTREACHED */
+	}
 
+	clearAllTool();
 
 	QString winTitle;
 	winTitle.append("ImageLabeler - ");
@@ -1748,8 +2219,11 @@ ImageLabeler::loadImage()
 	image_ID_ = list_images_widget_->count() - 1;
 	list_images_widget_->setCurrentRow(image_ID_);
 
-
-	addImage(&filename);
+	Image newImage;
+	newImage.image_ = filename;
+	newImage.labeled_ = 0;
+	newImage.pas_ = 0;
+	addImage(&newImage);
 
 	enableTools();
 }
@@ -1814,11 +2288,21 @@ ImageLabeler::loadImages()
 		/* NOTREACHED */
 	}
 
-	if (!image_->load(list_images_->at(0))) {
+	bool ret = 0;
+	if (list_images_->at(0).labeled_) {
+		QString labeled =
+			alterFileName(list_images_->at(0).image_, "_labeled");
+		labeled.append(".dat");
+		ret = loadInfo(labeled);
+	}
+	else
+		ret = image_->load(list_images_->at(0).image_);
+
+	if (!ret) {
 		return;
 		/* NOTREACHED */
 	}
-	current_image_ = list_images_->at(0);
+	current_image_ = list_images_->at(0).image_;
 	image_ID_ = 0;
 	list_images_widget_->setCurrentRow(image_ID_);
 
@@ -2100,10 +2584,12 @@ ImageLabeler::generateColors()
 		list_label_->item(itemNo)->setIcon(icon);
 		list_label_colors_.append(color);
 	}
+
+	image_holder_->update();
 }
 
 void
-ImageLabeler::setBBoxFromData(
+ImageLabeler::addBBoxFromData(
 	QString *aBBoxData,
 	int *ID
 )
@@ -2237,20 +2723,46 @@ ImageLabeler::BBoxFromString(
 }
 
 void
-ImageLabeler::setPolyFromData(
+ImageLabeler::addPoly(Polygon *poly)
+{
+	if (poly->poly.isEmpty() || poly->label_ID_ < 0) {
+		return;
+		/* NOTREACHED */
+	}
+
+	list_polygon_.append(poly);
+	addPolyArea(list_polygon_.count() - 1, *poly);
+
+}
+
+void
+ImageLabeler::addBBox(BoundingBox *bbox)
+{
+	if (bbox->rect.isEmpty() || bbox->label_ID_ < 0) {
+		return;
+		/* NOTREACHED */
+	}
+
+	list_bounding_box_.append(bbox);
+	addBBoxArea(list_bounding_box_.count() - 1, *bbox);
+
+}
+
+void
+ImageLabeler::addPolyFromData(
 	QString *aPolyData,
-	int *ID
+	int *labelID
 )
 {
 	Polygon *poly = new Polygon;
 	*poly = polyFromData(aPolyData);
 
-	if (poly->poly.isEmpty() || !ID) {
+	if (poly->poly.isEmpty() || !labelID) {
 		return;
 		/* NOTREACHED */
 	}
 
-	poly->label_ID_ = *ID;
+	poly->label_ID_ = *labelID;
 	list_polygon_.append(poly);
 	addPolyArea(list_polygon_.count() - 1, *poly);
 }
@@ -2516,6 +3028,12 @@ void ImageLabeler::clearLabelList()
 		);
 }
 
+void ImageLabeler::clearLabelColorList()
+{
+	list_label_colors_.clear();
+	list_label_colors_.append(0x0);
+}
+
 void
 ImageLabeler::enableTools()
 {
@@ -2675,6 +3193,8 @@ ImageLabeler::setLabelColor()
 	QIcon icon(iconPix);
 
 	current->setIcon(icon);
+
+	image_holder_->update();
 }
 
 void
@@ -2698,6 +3218,8 @@ ImageLabeler::setLabelColor(int anID, QColor aColor)
 	QIcon icon(iconPix);
 
 	item->setIcon(icon);
+
+	image_holder_->update();
 }
 
 void
@@ -2745,16 +3267,74 @@ ImageLabeler::interruptSearch()
 void
 ImageLabeler::selectImage(QListWidgetItem *anItem)
 {
-	if (!anItem || list_images_widget_->row(anItem) < 0)  {
+	if (!anItem || list_images_widget_->row(anItem) < 0 ||
+		list_images_->isEmpty())  {
 		return;
 		/* NOTREACHED */
 	}
+	clearAllTool();
+	clearLabelList();
+	clearLabelColorList();
 
 	image_ID_ = list_images_widget_->row(anItem);
 
-	image_->load(list_images_->at(image_ID_));
-	image_holder_->setPixmap(*image_);
-	image_holder_->resize(image_->size());
+	selectImage(image_ID_);
+//	if (list_images_->at(image_ID_).labeled_ &&
+//		!list_images_->at(image_ID_).pas_)
+//	{
+//		list_label_->clear();
+//		QString labeled =
+//			alterFileName(list_images_->at(image_ID_).image_, "_labeled");
+//		labeled.append(".dat");
+//		loadInfo(labeled);
+//	}
+//	else if (list_images_->at(image_ID_).labeled_ &&
+//		list_images_->at(image_ID_).pas_)
+//	{
+//		/* TODO: do the pascal file selecting */
+//		showWarning("this function doesn't work at the moment, sorry.");
+//	}
+//	else {
+//		current_image_ = list_images_->at(image_ID_).image_;
+//		image_->load(current_image_);
+//		image_holder_->setPixmap(*image_);
+//		image_holder_->resize(image_->size());
+//	}
+}
+
+bool
+ImageLabeler::selectImage(int anImageID)
+{
+	if (anImageID < 0 || list_images_->isEmpty() ||
+		list_images_->count() <= anImageID)
+	{
+		return false;
+		/* NOTREACHED */
+	}
+
+	if (list_images_->at(anImageID).labeled_ &&
+		!list_images_->at(anImageID).pas_)
+	{
+		list_label_->clear();
+		QString labeled =
+			alterFileName(list_images_->at(anImageID).image_, "_labeled");
+		labeled.append(".dat");
+		loadInfo(labeled);
+	}
+	else if (list_images_->at(anImageID).labeled_ &&
+		list_images_->at(anImageID).pas_)
+	{
+		/* TODO: do the pascal file selecting */
+		showWarning("this function doesn't work at the moment, sorry.");
+	}
+	else {
+		current_image_ = list_images_->at(anImageID).image_;
+		image_->load(current_image_);
+		image_holder_->setPixmap(*image_);
+		image_holder_->resize(image_->size());
+	}
+
+	return true;
 }
 
 void
@@ -2781,7 +3361,7 @@ ImageLabeler::removeImage()
 	list_images_->takeAt(num);
 
 	for (int i = num ; i < list_images_widget_->count(); i++) {
-		QString newStr = getFilenameFromPath(&(list_images_->at(i)));
+		QString newStr = getFilenameFromPath(&(list_images_->at(i).image_));
 		newStr.prepend(QString("%1: ").arg(i));
 		list_images_widget_->item(i)->setText(newStr);
 	}

+ 25 - 6
ImageLabeler.h

@@ -33,6 +33,12 @@ class QButtonGroup;
 class QDomDocument;
 class QDomElement;
 
+struct Image {
+	QString image_;
+	bool labeled_;
+	bool pas_;
+};
+
 class ImageLabeler : public QMainWindow
 {
 	Q_OBJECT
@@ -48,13 +54,15 @@ protected:
 	void showWarning(const QString text);
 	bool askForUnsavedData();
 	void loadLegendFromNode(QDomElement *anElement);
-	void setPolyFromData(
+	void addPoly(Polygon *poly);
+	void addBBox(BoundingBox *bbox);
+	void addPolyFromData(
 		QString *aPolyData,
-		int *ID
+		int *labelID
 		);
-	void setBBoxFromData(
+	void addBBoxFromData(
 		QString *aBBoxData,
-		int *ID
+		int *labelID
 		);
 	Polygon polyFromData(
 		QString *aPolyData
@@ -74,7 +82,11 @@ protected:
 	void disableTools();
 	void legendToXml(QDomDocument *aDoc, QDomElement *aRoot);
 	void objectsToXml(QDomDocument *aDoc, QDomElement *aRoot);
-	void addImage(QString *anImage);
+	void addImage(Image *anImage);
+	bool loadInfo(QString filename);
+	bool loadPascalFile(QString aFilename);
+	bool loadPascalPolys(QString aFilename);
+	bool selectImage(int anImageID);
 
 public:
 	ImageLabeler(QWidget *aParent = 0);
@@ -111,6 +123,8 @@ public slots:
 	void loadImage();
 	void loadImages();
 	void loadInfo();
+	void loadPascalFile();
+	void loadPascalPolys();
 	void loadLegendFromFile();
 	void setBoundingBoxTool(bool aButtonPressed);
 	void setPolygonTool(bool aButtonPressed);
@@ -119,6 +133,7 @@ public slots:
 	void clearAll();
 	void clearAllTool();
 	void clearLabelList();
+	void clearLabelColorList();
 	void areaListPopupMenu(const QPoint &aPos);
 	void labelListPopupMenu(const QPoint &aPos);
 	void setDescription(QString aDescription);
@@ -141,6 +156,7 @@ private:
 	/* menu */
 	QMenuBar *menu_bar_;
 	QMenu *menu_file_;
+	QMenu *menu_pascal_;
 	QMenu *menu_view_;
 	QMenu *menu_edit_;
 	QMenu *menu_help_;
@@ -153,6 +169,9 @@ private:
 	QAction *action_save_segmented_;
 	QAction *action_save_legend_;
 	QAction *action_quit_;
+	/* menu pascal */
+	QAction *action_load_pascal_file_;
+	QAction *action_load_pascal_poly_;
 	/* menu view */
 	QAction *action_view_normal_;
 	QAction *action_view_segmented_;
@@ -236,7 +255,7 @@ private:
 	int image_ID_;
 
 	QString image_description_;
-	QStringList *list_images_;
+	QList< Image > *list_images_;
 	//QStringList::iterator current_image_;
 	QString current_image_;
 	QString segmented_image_;

+ 4 - 8
Makefile

@@ -1,9 +1,9 @@
 #############################################################################
 # Makefile for building: ImageLabeler
-# Generated by qmake (2.01a) (Qt 4.7.1) on: Tue Oct 11 14:53:52 2011
+# Generated by qmake (2.01a) (Qt 4.6.3) on: Di. Okt 18 10:14:46 2011
 # Project:  ImageLabeler.pro
 # Template: app
-# Command: /usr/bin/qmake CONFIG+=debug_and_release -o Makefile ImageLabeler.pro
+# Command: /usr/bin/qmake -unix CONFIG+=debug_and_release -o Makefile ImageLabeler.pro
 #############################################################################
 
 first: release
@@ -67,8 +67,6 @@ Makefile: ImageLabeler.pro  /usr/share/qt4/mkspecs/default/qmake.conf /usr/share
 		/usr/share/qt4/mkspecs/common/unix.conf \
 		/usr/share/qt4/mkspecs/common/linux.conf \
 		/usr/share/qt4/mkspecs/qconfig.pri \
-		/usr/share/qt4/mkspecs/modules/qt_phonon.pri \
-		/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \
 		/usr/share/qt4/mkspecs/features/qt_functions.prf \
 		/usr/share/qt4/mkspecs/features/qt_config.prf \
 		/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
@@ -88,13 +86,11 @@ Makefile: ImageLabeler.pro  /usr/share/qt4/mkspecs/default/qmake.conf /usr/share
 		/usr/lib64/libQtXml.prl \
 		/usr/lib64/libQtCore.prl \
 		/usr/lib64/libQtGui.prl
-	$(QMAKE) CONFIG+=debug_and_release -o Makefile ImageLabeler.pro
+	$(QMAKE) -unix CONFIG+=debug_and_release -o Makefile ImageLabeler.pro
 /usr/share/qt4/mkspecs/common/g++.conf:
 /usr/share/qt4/mkspecs/common/unix.conf:
 /usr/share/qt4/mkspecs/common/linux.conf:
 /usr/share/qt4/mkspecs/qconfig.pri:
-/usr/share/qt4/mkspecs/modules/qt_phonon.pri:
-/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri:
 /usr/share/qt4/mkspecs/features/qt_functions.prf:
 /usr/share/qt4/mkspecs/features/qt_config.prf:
 /usr/share/qt4/mkspecs/features/exclusive_builds.prf:
@@ -115,7 +111,7 @@ Makefile: ImageLabeler.pro  /usr/share/qt4/mkspecs/default/qmake.conf /usr/share
 /usr/lib64/libQtCore.prl:
 /usr/lib64/libQtGui.prl:
 qmake: qmake_all FORCE
-	@$(QMAKE) CONFIG+=debug_and_release -o Makefile ImageLabeler.pro
+	@$(QMAKE) -unix CONFIG+=debug_and_release -o Makefile ImageLabeler.pro
 
 qmake_all: FORCE
 

+ 6 - 5
Makefile.Debug

@@ -1,6 +1,6 @@
 #############################################################################
 # Makefile for building: ImageLabeler
-# Generated by qmake (2.01a) (Qt 4.7.1) on: Tue Oct 11 14:53:52 2011
+# Generated by qmake (2.01a) (Qt 4.6.3) on: Di. Okt 18 10:14:46 2011
 # Project:  ImageLabeler.pro
 # Template: app
 #############################################################################
@@ -65,8 +65,6 @@ DIST          = /usr/share/qt4/mkspecs/common/g++.conf \
 		/usr/share/qt4/mkspecs/common/unix.conf \
 		/usr/share/qt4/mkspecs/common/linux.conf \
 		/usr/share/qt4/mkspecs/qconfig.pri \
-		/usr/share/qt4/mkspecs/modules/qt_phonon.pri \
-		/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \
 		/usr/share/qt4/mkspecs/features/qt_functions.prf \
 		/usr/share/qt4/mkspecs/features/qt_config.prf \
 		/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
@@ -117,7 +115,7 @@ $(TARGET):  $(OBJECTS)
 	$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
 
 qmake:  FORCE
-	@$(QMAKE) CONFIG+=debug_and_release -o Makefile.Debug ImageLabeler.pro
+	@$(QMAKE) -unix CONFIG+=debug_and_release -o Makefile.Debug ImageLabeler.pro
 
 dist: 
 	@$(CHK_DIR_EXISTS) debug/ImageLabeler1.0.0 || $(MKDIR) debug/ImageLabeler1.0.0 
@@ -156,6 +154,7 @@ debug/moc_ImageHolder.cpp: ImageHolder.h
 
 debug/moc_ImageLabeler.cpp: ImageHolder.h \
 		ImageDescriptionForm.h \
+		OptionsForm.h \
 		ImageLabeler.h
 	/usr/bin/moc $(DEFINES) $(INCPATH) ImageLabeler.h -o debug/moc_ImageLabeler.cpp
 
@@ -194,12 +193,14 @@ debug/ImageHolder.o: ImageHolder.cpp ImageHolder.h \
 debug/ImageLabeler.o: ImageLabeler.cpp ImageLabeler.h \
 		ImageHolder.h \
 		ImageDescriptionForm.h \
+		OptionsForm.h \
 		functions.h
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o debug/ImageLabeler.o ImageLabeler.cpp
 
 debug/main.o: main.cpp ImageLabeler.h \
 		ImageHolder.h \
-		ImageDescriptionForm.h
+		ImageDescriptionForm.h \
+		OptionsForm.h
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o debug/main.o main.cpp
 
 debug/moc_OptionsForm.o: debug/moc_OptionsForm.cpp 

+ 8 - 7
Makefile.Release

@@ -1,6 +1,6 @@
 #############################################################################
 # Makefile for building: ImageLabeler
-# Generated by qmake (2.01a) (Qt 4.7.1) on: Tue Oct 11 14:53:52 2011
+# Generated by qmake (2.01a) (Qt 4.6.3) on: Di. Okt 18 10:14:46 2011
 # Project:  ImageLabeler.pro
 # Template: app
 #############################################################################
@@ -10,8 +10,8 @@
 CC            = gcc
 CXX           = g++
 DEFINES       = -DQT_NO_DEBUG -DQT_XML_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
-CFLAGS        = -m64 -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
-CXXFLAGS      = -m64 -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES)
+CFLAGS        = -m64 -pipe -O2 -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -W -D_REENTRANT $(DEFINES)
+CXXFLAGS      = -m64 -pipe -O2 -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -W -D_REENTRANT $(DEFINES)
 INCPATH       = -I/usr/share/qt4/mkspecs/default -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include/QtXml -I/usr/include -Irelease
 LINK          = g++
 LFLAGS        = -m64 -Wl,-O1
@@ -65,8 +65,6 @@ DIST          = /usr/share/qt4/mkspecs/common/g++.conf \
 		/usr/share/qt4/mkspecs/common/unix.conf \
 		/usr/share/qt4/mkspecs/common/linux.conf \
 		/usr/share/qt4/mkspecs/qconfig.pri \
-		/usr/share/qt4/mkspecs/modules/qt_phonon.pri \
-		/usr/share/qt4/mkspecs/modules/qt_webkit_version.pri \
 		/usr/share/qt4/mkspecs/features/qt_functions.prf \
 		/usr/share/qt4/mkspecs/features/qt_config.prf \
 		/usr/share/qt4/mkspecs/features/exclusive_builds.prf \
@@ -117,7 +115,7 @@ $(TARGET):  $(OBJECTS)
 	$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
 
 qmake:  FORCE
-	@$(QMAKE) CONFIG+=debug_and_release -o Makefile.Release ImageLabeler.pro
+	@$(QMAKE) -unix CONFIG+=debug_and_release -o Makefile.Release ImageLabeler.pro
 
 dist: 
 	@$(CHK_DIR_EXISTS) release/ImageLabeler1.0.0 || $(MKDIR) release/ImageLabeler1.0.0 
@@ -156,6 +154,7 @@ release/moc_ImageHolder.cpp: ImageHolder.h
 
 release/moc_ImageLabeler.cpp: ImageHolder.h \
 		ImageDescriptionForm.h \
+		OptionsForm.h \
 		ImageLabeler.h
 	/usr/bin/moc $(DEFINES) $(INCPATH) ImageLabeler.h -o release/moc_ImageLabeler.cpp
 
@@ -194,12 +193,14 @@ release/ImageHolder.o: ImageHolder.cpp ImageHolder.h \
 release/ImageLabeler.o: ImageLabeler.cpp ImageLabeler.h \
 		ImageHolder.h \
 		ImageDescriptionForm.h \
+		OptionsForm.h \
 		functions.h
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o release/ImageLabeler.o ImageLabeler.cpp
 
 release/main.o: main.cpp ImageLabeler.h \
 		ImageHolder.h \
-		ImageDescriptionForm.h
+		ImageDescriptionForm.h \
+		OptionsForm.h
 	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o release/main.o main.cpp
 
 release/moc_OptionsForm.o: release/moc_OptionsForm.cpp 

+ 22 - 2
functions.cpp

@@ -65,9 +65,10 @@ getNumFromString(
 }
 
 /*
- * adds given suffix to the file name and removes path from it
+ * adds given suffix to the file name
  */
-QString alterFileName(const QString &aFilename, const QString &aSuffix)
+QString
+alterFileName(const QString &aFilename, const QString &aSuffix)
 {
 	/* altering the name of a new file */
 	QString newFileName = aFilename;
@@ -80,12 +81,31 @@ QString alterFileName(const QString &aFilename, const QString &aSuffix)
 
 	newFileName.insert(dotPos, aSuffix);
 
+	return newFileName;
+}
+
+QString
+removePath(const QString &aFilename)
+{
+	QString newFileName = aFilename;
+
 	int slashPos = newFileName.lastIndexOf('/');
 	newFileName.remove(0, slashPos);
 
 	return newFileName;
 }
 
+QString
+getPathFromFilename(const QString &aFilename)
+{
+	QString path = aFilename;
+
+	int slashPos = path.lastIndexOf('/');
+	path = path.mid(0, slashPos + 1);
+
+	return path;
+}
+
 QString
 getDirFromPath(const QString *aPath)
 {

+ 14 - 1
functions.h

@@ -24,6 +24,19 @@ int getNumFromString(
 	const QString &aSecondStr,
 	bool *anOkFlag
 	);
-QString alterFileName(const QString &aFilename, const QString &aSuffix);
+QString alterFileName(
+	const QString &aFilename,
+	const QString &aSuffix
+	);
+QString removePath(
+	const QString &aFilename
+	);
+QString getPathFromFilename(
+	const QString &aFilename
+	);
 
 #endif /* __FUNCTIONS_H__ */
+
+/*
+ *
+ */

+ 4 - 0
main.cpp

@@ -15,3 +15,7 @@ int main(int argc, char *argv[])
 
     return app.exec();
 }
+
+/*
+ *
+ */