|
@@ -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);
|
|
|
}
|