Commit 9e140b118e6c174c1f1707558f96228c2a995ff5

Authored by Scott Klum
1 parent dc4eaa32

Added support for the MUCT dataset format for shapes via shapeGallery

Showing 1 changed file with 73 additions and 0 deletions
openbr/plugins/gallery.cpp
... ... @@ -1588,6 +1588,79 @@ class landmarksGallery : public Gallery
1588 1588  
1589 1589 BR_REGISTER(Gallery, landmarksGallery)
1590 1590  
  1591 +/*!
  1592 + * \ingroup galleries
  1593 + * \brief MUCT format for specifying a shape for a file
  1594 + * \author Scott Klum
  1595 + *
  1596 + * http://www.milbo.org/muct/
  1597 + */
  1598 +class shapeGallery : public Gallery
  1599 +{
  1600 + Q_OBJECT
  1601 +
  1602 + QMap<unsigned long, QString> attributes;
  1603 +
  1604 + TemplateList readBlock(bool *done)
  1605 + {
  1606 + *done = true;
  1607 + TemplateList templates;
  1608 + QStringList lines = QtUtils::readLines(file);
  1609 + for (int i=0; i<lines.size(); i++) {
  1610 + if (lines[i].at(0) == '#' || lines[i].at(0) == '}') continue;
  1611 +
  1612 + // First non-comment line should be "attributes filename"
  1613 + QStringList values = lines[i].split(' ');
  1614 +
  1615 + // Assume jpg
  1616 + File file(values.back()+".jpg");
  1617 +
  1618 + bool ok;
  1619 + unsigned long attributeKey = values.front().toULong(&ok,16);
  1620 +
  1621 + if (attributeKey >= 2147483648) /* Don't use face detection results for now */ {
  1622 + i+=2; continue;
  1623 + } else if (ok && attributes.contains(attributeKey)) {
  1624 + file.set(attributes[attributeKey],true);
  1625 + }
  1626 +
  1627 + // Next line should be "{ numLandmarks dimensions"
  1628 + // We don't current support more than two dimensions for landmarks
  1629 + values = lines[++i].split(' ');
  1630 + int numLandmarks = values.at(1).toInt(&ok);
  1631 + if (ok) {
  1632 + QList<QPointF> points; points.reserve(numLandmarks);
  1633 + for (int j=0; j<numLandmarks; j++) {
  1634 + const QList<float> vals = QtUtils::toFloats(lines[++i].split(' '));
  1635 + points.append(QPointF(vals[0], vals[1]));
  1636 + }
  1637 + file.setPoints(points);
  1638 + }
  1639 + templates.append(file);
  1640 + }
  1641 + return templates;
  1642 + }
  1643 +
  1644 + void write(const Template &t)
  1645 + {
  1646 + (void) t;
  1647 + qFatal("Not implemented.");
  1648 + }
  1649 +
  1650 + void init()
  1651 + {
  1652 + // attribute codes
  1653 + attributes[4] = "Glasses";
  1654 + attributes[8] = "Beard";
  1655 + attributes[16] = "Mustache";
  1656 + attributes[256] = "BadImg";
  1657 + attributes[512] = "Cropped";
  1658 + attributes[2048] = "BadEye";
  1659 + }
  1660 +};
  1661 +
  1662 +BR_REGISTER(Gallery, shapeGallery)
  1663 +
1591 1664 #ifdef CVMATIO
1592 1665  
1593 1666 using namespace cv;
... ...