|
@@ -23,6 +23,8 @@
|
|
|
#include <QDomNode>
|
|
|
#include <QDomElement>
|
|
|
#include <QPoint>
|
|
|
+#include <QStringList>
|
|
|
+#include <QVariant>
|
|
|
|
|
|
#endif //NICE_USELIB_QT4_XML
|
|
|
|
|
@@ -115,14 +117,11 @@ ImageInfo::loadImageInfo(const string &aFilename)
|
|
|
/* tags */
|
|
|
else if (element.tagName() == "tags") {
|
|
|
string_buffer = element.text();
|
|
|
- if (string_buffer.isEmpty()) {
|
|
|
- rootNode = rootNode.nextSibling();
|
|
|
- cout << "tags are empty\n";
|
|
|
- continue;
|
|
|
- }
|
|
|
- QByteArray array = string_buffer.toAscii();
|
|
|
- //TODO: make parsing into the string list
|
|
|
- tags_ = string(array.data());
|
|
|
+ if ( !string_buffer.isEmpty()) {
|
|
|
+ QByteArray array = string_buffer.toAscii();
|
|
|
+ //TODO: make parsing into the string list
|
|
|
+ tags_ = string(array.data());
|
|
|
+ }
|
|
|
}
|
|
|
/* legend */
|
|
|
else if (element.tagName() == "legend") {
|
|
@@ -152,19 +151,41 @@ ImageInfo::loadImageInfo(const string &aFilename)
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- string_buffer = subElement.text();
|
|
|
+ // try reading a unique object/bounding box id, which identifies
|
|
|
+ // this object against all others (not a label)
|
|
|
+ string_buffer = subElement.attribute("uniqueObjectId");
|
|
|
+ ok = 1;
|
|
|
+ int uniqueObjectId = string_buffer.toInt(&ok, 10);
|
|
|
+ if(!ok)
|
|
|
+ uniqueObjectId = -1;
|
|
|
|
|
|
+
|
|
|
+ string_buffer = subElement.text();
|
|
|
if (subElement.tagName() == "bbox") {
|
|
|
- BoundingBox bbox = BBoxFromData(&string_buffer, id);
|
|
|
- //bbox.setID(id);
|
|
|
- bboxes_.push_back(bbox);
|
|
|
+ BoundingBox bbox;
|
|
|
+ bool bValid = BBoxFromData(&string_buffer, id, bbox);
|
|
|
+ if( bValid )
|
|
|
+ {
|
|
|
+ bbox.unique_id_ = uniqueObjectId;
|
|
|
+
|
|
|
+ bboxes_.push_back(bbox);
|
|
|
+ }
|
|
|
}
|
|
|
if (subElement.tagName() == "poly") {
|
|
|
- Polygon poly = polyFromData(&string_buffer);
|
|
|
- poly.setID(id);
|
|
|
- polys_.push_back(poly);
|
|
|
+ Polygon poly;
|
|
|
+ bool bValid = polyFromData(&string_buffer, poly);
|
|
|
+ if(bValid)
|
|
|
+ {
|
|
|
+ poly.setID(id);
|
|
|
+ poly.unique_id_ = uniqueObjectId;
|
|
|
+
|
|
|
+ polys_.push_back(poly);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
subNode = subNode.nextSibling();
|
|
|
}
|
|
|
}
|
|
@@ -316,120 +337,81 @@ ImageInfo::loadCategoryInfo(QDomElement *anElement)
|
|
|
/*!
|
|
|
* format is x;y;w;h where w - width and h - height
|
|
|
*/
|
|
|
-BoundingBox
|
|
|
-ImageInfo::BBoxFromData(
|
|
|
- QString *aBBoxData,
|
|
|
- int &id
|
|
|
-)
|
|
|
+bool ImageInfo::BBoxFromData( QString *aBBoxData, int &id, BoundingBox &p_bbox )
|
|
|
{
|
|
|
- BoundingBox bbox;
|
|
|
- bbox.setID(id);
|
|
|
-
|
|
|
- QString buffer;
|
|
|
- int startPos = 0;
|
|
|
- bool ok = 1;
|
|
|
-
|
|
|
- int counter = 0;
|
|
|
- for (int i = 0; i < aBBoxData->size(); i++) {
|
|
|
- if (';' != aBBoxData->at(i))
|
|
|
- continue;
|
|
|
-
|
|
|
- buffer = aBBoxData->mid(startPos, i - startPos);
|
|
|
-
|
|
|
- int bboxData = buffer.toInt(&ok, 10);
|
|
|
- if (!ok) {
|
|
|
- cout <<
|
|
|
- "BBoxFromData: "
|
|
|
- "bbox format is corrupted\n";
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (!counter) {
|
|
|
- bbox.setTopLeft(bboxData, 0);
|
|
|
- counter++;
|
|
|
- }
|
|
|
- else if (1 == counter) {
|
|
|
- int x = bbox.topLeft().x;
|
|
|
- bbox.setTopLeft(x, bboxData);
|
|
|
- counter++;
|
|
|
- }
|
|
|
- else if (2 == counter) {
|
|
|
- bbox.setWidth(bboxData);
|
|
|
- counter++;
|
|
|
- }
|
|
|
- else if (3 == counter) {
|
|
|
- bbox.setHeight(bboxData);
|
|
|
- counter++;
|
|
|
- }
|
|
|
-
|
|
|
- startPos = i + 1;
|
|
|
- }
|
|
|
-
|
|
|
- if (!bbox.isValid() || !ok) {
|
|
|
- cout <<
|
|
|
- "BBoxFromData: "
|
|
|
- "bbox format is corrupted\n";
|
|
|
- bbox.setTopLeft(0, 0);
|
|
|
- bbox.setBottomRight(0, 0);
|
|
|
- }
|
|
|
|
|
|
- return bbox;
|
|
|
+ p_bbox.setID(id);
|
|
|
+
|
|
|
+ QStringList coordsList = aBBoxData->split(";", QString::SkipEmptyParts);
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if( coordsList.size() == 4)
|
|
|
+ {
|
|
|
+ int x = QVariant(coordsList[0]).toInt();
|
|
|
+ int y = QVariant(coordsList[1]).toInt();
|
|
|
+ int w = QVariant(coordsList[2]).toInt();
|
|
|
+ int h = QVariant(coordsList[3]).toInt();
|
|
|
+
|
|
|
+ p_bbox.setTopLeft(x,y);
|
|
|
+ p_bbox.setWidth( w );
|
|
|
+ p_bbox.setHeight( h );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout <<
|
|
|
+ "BBoxFromData: "
|
|
|
+ "bbox format is corrupted\n";
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(std::exception &e)
|
|
|
+ {
|
|
|
+ std::cout << "BBoxFromData: exception:" << e.what() << std::endl;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( !p_bbox.isValid() )
|
|
|
+ {
|
|
|
+ std::cout << "BBoxFromData not valid:"<< aBBoxData->toStdString() << std::endl;
|
|
|
+ p_bbox.setTopLeft(0, 0);
|
|
|
+ p_bbox.setBottomRight(0, 0);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
//! A protected member parsing string data and returning a Polygon from it
|
|
|
/*!
|
|
|
* format is x0;y0;x1;y1;...
|
|
|
*/
|
|
|
-Polygon
|
|
|
-ImageInfo::polyFromData(
|
|
|
- QString *aPolyData
|
|
|
-)
|
|
|
+bool ImageInfo::polyFromData( QString *aPolyData, Polygon &p_Poly)
|
|
|
{
|
|
|
- Polygon poly;
|
|
|
- QPoint point;
|
|
|
- QString buffer;
|
|
|
- int startPos = 0;
|
|
|
- bool ok = 1;
|
|
|
- /* indicates whether coordinate x or y */
|
|
|
- bool evenFlag = 0;
|
|
|
-
|
|
|
- for (int i = 0; i < aPolyData->size(); i++) {
|
|
|
- /* ";" is a separator */
|
|
|
- if (';' != aPolyData->at(i))
|
|
|
- continue;
|
|
|
-
|
|
|
- buffer = aPolyData->mid(startPos, i - startPos);
|
|
|
-
|
|
|
- int polyCoor = buffer.toInt(&ok, 10);
|
|
|
- if (!ok) {
|
|
|
- cout <<
|
|
|
- "polyFromData: "
|
|
|
- "poly format is corrupted\n";
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (!evenFlag) {
|
|
|
- point.setX(polyCoor);
|
|
|
- evenFlag = 1;
|
|
|
- }
|
|
|
- else {
|
|
|
- point.setY(polyCoor);
|
|
|
- poly.push(point.x(), point.y());
|
|
|
- evenFlag = 0;
|
|
|
- }
|
|
|
- startPos = i + 1;
|
|
|
- }
|
|
|
-
|
|
|
- /* last coordinate was Xi what means an error or
|
|
|
- last converting from string was not successful */
|
|
|
- if (evenFlag || !ok) {
|
|
|
- cout <<
|
|
|
- "polyFromData: "
|
|
|
- "poly format is corrupted\n";
|
|
|
- //poly.clear();
|
|
|
- }
|
|
|
-
|
|
|
- return poly;
|
|
|
+ QStringList coordsList = aPolyData->split(";", QString::SkipEmptyParts);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if( coordsList.size() % 2 == 0)
|
|
|
+ {
|
|
|
+ for( int i = 0; i < coordsList.size(); i += 2)
|
|
|
+ {
|
|
|
+ p_Poly.push( QVariant(coordsList[i]).toInt(),
|
|
|
+ QVariant(coordsList[i+1]).toInt() );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout << "polyFromData: not valid (coordinates not multiple of two)" << std::endl;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(std::exception &e)
|
|
|
+ {
|
|
|
+ std::cout << "polyFromData: exception:" << e.what() << std::endl;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
//!
|