Example #1
0
    void pairwiseCompare(File targetGallery, File queryGallery, File output)
    {
        qDebug("Pairwise comparing %s and %s%s", qPrintable(targetGallery.flat()),
               qPrintable(queryGallery.flat()),
               output.isNull() ? "" : qPrintable(" to " + output.flat()));

        if (distance.isNull()) qFatal("Null distance.");

        if (queryGallery == ".") queryGallery = targetGallery;

        QScopedPointer<Gallery> t, q;
        FileList targetFiles, queryFiles;
        retrieveOrEnroll(targetGallery, t, targetFiles);
        retrieveOrEnroll(queryGallery, q, queryFiles);

        if (t->files().length() != q->files().length() )
            qFatal("Dimension mismatch in pairwise compare");

        TemplateList queries = q->read();
        TemplateList targets = t->read();

        // Use a single file for one of the dimensions so that the output makes the right size file
        FileList dummyTarget;
        dummyTarget.append(targets[0]);
        QScopedPointer<Output> realOutput(Output::make(output, dummyTarget, queryFiles));

        realOutput->set_blockRows(INT_MAX);
        realOutput->set_blockCols(INT_MAX);
        realOutput->setBlock(0,0);
        for (int i=0; i < queries.length(); i++)
        {
            float res = distance->compare(queries[i], targets[i]);
            realOutput->setRelative(res, 0,i);
        }
    }
Example #2
0
FileList* DataTransfer::files() const {
  FileList* files = FileList::create();
  if (!canReadData())
    return files;

  for (size_t i = 0; i < m_dataObject->length(); ++i) {
    if (m_dataObject->item(i)->kind() == DataObjectItem::FileKind) {
      Blob* blob = m_dataObject->item(i)->getAsFile();
      if (blob && blob->isFile())
        files->append(toFile(blob));
    }
  }

  return files;
}
Example #3
0
    FileList enroll(File input, File gallery = File())
    {
        FileList files;

        qDebug("Enrolling %s%s", qPrintable(input.flat()),
               gallery.isNull() ? "" : qPrintable(" to " + gallery.flat()));

        if (gallery.name.isEmpty()) {
            if (input.name.isEmpty()) return FileList();
            else                      gallery = getMemoryGallery(input);
        }
        TemplateList data(TemplateList::fromGallery(input));

        if (gallery.contains("append"))
        {
            // Remove any templates which are already in the gallery
            QScopedPointer<Gallery> g(Gallery::make(gallery));
            files = g->files();
            QSet<QString> nameSet = QSet<QString>::fromList(files.names());
            for (int i = data.size() - 1; i>=0; i--) {
                if (nameSet.contains(data[i].file.name))
                {
                    data.removeAt(i);
                }
            }
        }

        if (data.empty())
            return files;

        // Store steps for ProgressCounter
        Globals->currentStep = 0;
        Globals->totalSteps = data.length();

        // Trust me, this makes complete sense.
        // We're just going to make a pipe with a placeholder first transform
        QString pipeDesc = "Identity+GalleryOutput("+gallery.flat()+")+ProgressCounter("+QString::number(data.length())+")+Discard";
        QScopedPointer<Transform> basePipe(Transform::make(pipeDesc,NULL));

        CompositeTransform * downcast = dynamic_cast<CompositeTransform *>(basePipe.data());
        if (downcast == NULL)
            qFatal("downcast failed?");

        // replace that placeholder with the current algorithm
        downcast->transforms[0] = this->transform.data();

        // call init on the pipe to collapse the algorithm (if its top level is a pipe)
        downcast->init();

        // Next, we make a Stream (with placeholder transform)
        QString streamDesc = "Stream(Identity, readMode=DistributeFrames)";
        QScopedPointer<Transform> baseStream(Transform::make(streamDesc, NULL));
        WrapperTransform * wrapper = dynamic_cast<WrapperTransform *> (baseStream.data());

        // replace that placeholder with the pipe we built
        wrapper->transform = downcast;

        // and get the final stream's stages by reinterpreting the pipe. Perfectly straightforward.
        wrapper->init();

        Globals->startTime.start();

        wrapper->projectUpdate(data,data);

        files.append(data.files());

        return files;
    }
Example #4
0
/**** BEE ****/
FileList BEE::readSigset(const File &sigset, bool ignoreMetadata)
{
    FileList fileList;

#ifndef BR_EMBEDDED
    QDomDocument doc(sigset.fileName());
    QFile file(sigset.resolved());
    bool success;
    success = file.open(QIODevice::ReadOnly); if (!success) qFatal("Unable to open %s for reading.", qPrintable(sigset));
    success = doc.setContent(&file);

    file.close();

    if (!success) {
        qWarning("Unable to parse %s.", qPrintable(sigset));
        return fileList;
    }

    QDomElement docElem = doc.documentElement();
    if (docElem.nodeName() != "biometric-signature-set")
        return fileList;

    QDomNode subject = docElem.firstChild();
    while (!subject.isNull()) {
        // Looping through subjects
        QDomNode fileNode = subject.firstChild();
        QDomElement d = subject.toElement();
        QString name = d.attribute("name");
        while (!fileNode.isNull()) {
            // Looping through files
            File file("", name);

            QDomElement e = fileNode.toElement();
            QDomNamedNodeMap attributes = e.attributes();
            for (int i=0; i<attributes.length(); i++) {
                const QString key = attributes.item(i).nodeName();
                const QString value = attributes.item(i).nodeValue();
                if      (key == "file-name") file.name = value;
                else if (!ignoreMetadata)    file.set(key, value);
            }

            // add bounding boxes, if they exist (will be child elements of <presentation>)
            if (fileNode.hasChildNodes()) {
                QList<QRectF> rects;
                QDomNodeList bboxes = fileNode.childNodes();
                for (int i=0; i<bboxes.length(); i++) {
                    QDomElement bbox = bboxes.at(i).toElement();
                    qreal x = bbox.attribute("x").toDouble();
                    qreal y = bbox.attribute("y").toDouble();
                    qreal width = bbox.attribute("width").toDouble();
                    qreal height = bbox.attribute("height").toDouble();
                    rects += QRectF(x, y, width, height);
                }
                file.setRects(rects);
            }

            if (file.name.isEmpty()) qFatal("Missing file-name in %s.", qPrintable(sigset));
            fileList.append(file);

            fileNode = fileNode.nextSibling();
        }
        subject = subject.nextSibling();
    }
#else // BR_EMBEDDED
    (void) sigset;
    (void) ignoreMetadata;
#endif // BR_EMBEDDED

    return fileList;
}
Example #5
0
    FileList enroll(File input, File gallery = File())
    {
        FileList files;

        qDebug("Enrolling %s%s", qPrintable(input.flat()),
               gallery.isNull() ? "" : qPrintable(" to " + gallery.flat()));

        if (gallery.name.isEmpty()) {
            if (input.name.isEmpty()) return FileList();
            else                      gallery = getMemoryGallery(input);
        }

        bool multiProcess = Globals->file.getBool("multiProcess", false);
        bool fileExclusion = false;

        // In append mode, we will exclude any templates with filenames already present in the output gallery
        if (gallery.contains("append") && gallery.exists() ) {
            FileList::fromGallery(gallery,true);
            fileExclusion = true;
        }

        Gallery * temp = Gallery::make(input);
        qint64 total = temp->totalSize();

        Globals->currentStep = 0;
        Globals->totalSteps = total;

        QScopedPointer<Transform> basePipe;

        QString pipeDesc = "GalleryOutput("+gallery.flat()+")+ProgressCounter("+QString::number(total)+")+Discard";

        if (!multiProcess) {
            basePipe.reset(Transform::make(pipeDesc,NULL));
            CompositeTransform * downcast = dynamic_cast<CompositeTransform *>(basePipe.data());

            if (downcast == NULL) qFatal("downcast failed?");

            downcast->transforms.prepend(this->transform.data());
            if (fileExclusion) {
                Transform * temp = Transform::make("FileExclusion(" + gallery.flat() + ")", downcast);
                downcast->transforms.prepend(temp);
            }

            // call init on the pipe to collapse the algorithm (if its top level is a pipe)
            downcast->init();
        }
        else {
            pipeDesc = "ProcessWrapper("+transformString+")"+pipeDesc;
            if (fileExclusion)
                pipeDesc = "FileExclusion(" + gallery.flat() +")" + pipeDesc;

            basePipe.reset(Transform::make(pipeDesc,NULL));
        }

        // Next, we make a Stream (with placeholder transform)
        QString streamDesc = "Stream(readMode=StreamGallery)";
        QScopedPointer<Transform> baseStream(Transform::make(streamDesc, NULL));
        WrapperTransform * wrapper = dynamic_cast<WrapperTransform *> (baseStream.data());

        // replace that placeholder with the pipe we built
        wrapper->transform = basePipe.data();

        // and get the final stream's stages by reinterpreting the pipe. Perfectly straightforward.
        wrapper->init();

        Globals->startTime.start();

        TemplateList data, output;
        data.append(input);
        wrapper->projectUpdate(data, output);

        files.append(output.files());

        return files;
    }