Beispiel #1
0
void MusicScanner::saveCache(const QString &cache, MusicLibraryItemRoot *lib)
{
    lastCacheProg=-1;
    writeProgress(0.0);
    lib->toXML(cache, QDateTime(), this);
    emit cacheSaved();
}
Beispiel #2
0
void
makeDifferenceImages (char *imageDirectory, char *imageList, char *distanceMatrix, int maxRank, int reqNIntra, int reqNExtra, Matrix *intrapersonal, Matrix *extrapersonal)
{
    ImageList* imlist;
    void *nameList = NULL;
    char **nameArray;
    void *subjList = NULL;
    int *subjArray, *shuffledIndices, **sortedBySimilarityToProbe;
    int subjId, probeIdx, galleryIdx, idx, nIntrapersonal, nExtrapersonal, rank, i, numPixels;
    int nImages;
    /* size_t trash; */
    Matrix sourceImages, intraImages, extraImages;
    ImageList *replicate, *subject;
    char *subjName;

    /* Read in a list of all the images */

    imlist = getImageNames (imageList, &nImages);
    subjId = 0;
    for EACH_SUBJECT (imlist, subject) {
        for EACH_REPLICATE (subject, replicate) {
            subjName = strdup (replicate->filename);
            listAccumulate (&nameList, &subjName, sizeof (char *));
            listAccumulate (&subjList, &subjId,   sizeof (int));
            writeProgress ("Reading subjects list", subjId, 0);
        }
        subjId++;
    }
/*
This function reads images in to a vector.  That vector is then mean subtracted
and then projected onto an optimal basis (PCA, LDA or LPP). Returned is a matrix
that contains the images after they have been projected onto the subspace.
*/
Matrix
readAndProjectImages (Subspace *s, char *imageNamesFile, char *imageDirectory, int *numImages, ImageList **srt)
{
    int i, j;
    Matrix images, vector, smallVector;
    char name[FILE_LINE_LENGTH];
    ImageList *subject, *replicate;

    DEBUG(1, "Reading training file names from file");

    *srt = getImageNames(imageNamesFile, numImages);

    DEBUG_CHECK(*srt, "Error: header no imagenames found in file image list file");

    /* Automatically determine number of pixels in images    */
    sprintf(name, "%s/%s", imageDirectory, (*srt)->filename);
    DEBUG(1, "Autodetecting number of pixels, i.e. vector length based on the size of image 0.");
    DEBUG_CHECK (autoFileLength(name) == s->numPixels, "Images sizes do not match subspace basis vector size");
    DEBUG_INT(1, "Vector length", s->numPixels);
    DEBUG_CHECK(s->numPixels > 0, "Error positive value required for a Vector Length");

    /*Images stored in the columns of a matrix */
    DEBUG(1, "Allocating image matrix");

    images = makeMatrix(s->basis->col_dim, *numImages);
    vector = makeMatrix(s->numPixels, 1);

    i = 0;
    for (subject = *srt; subject; subject = subject->next_subject) {
        for (replicate = subject; replicate; replicate = replicate->next_replicate) {
            if (debuglevel > 0)
                printf("%s ", replicate->filename);
            sprintf(name, "%s/%s", imageDirectory, replicate->filename);
            replicate->imageIndex = i;
            readFile(name, 0, vector);

            writeProgress("Reading images", i,*numImages);

            smallVector = centerThenProjectImages(s, vector);

            /* Copy the smaller vector into the image matrix*/
            for (j = 0; j < smallVector->row_dim; j++) {
                ME(images, j, i) = ME(smallVector, j, 0);
            }
            freeMatrix(smallVector);
            i++;  /* increament the image index */
        }
        if (debuglevel > 0)
            printf("\n");
    }

    return images;
}
Beispiel #4
0
void MusicScanner::scan(const QString &folder, const QString &cacheFile, bool readCache, const QSet<FileOnlySong> &existingSongs)
{
    lastCacheProg=-1;
    if (!cacheFile.isEmpty() && readCache) {
        MusicLibraryItemRoot *lib=new MusicLibraryItemRoot;
        MusicLibraryModel::convertCache(cacheFile);
        readProgress(0.0);
        if (lib->fromXML(cacheFile, QDateTime(), folder)) {
            lib->applyGrouping();
            if (!stopRequested) {
                emit libraryUpdated(lib);
            } else {
                delete lib;
            }
            return;
        } else {
            delete lib;
        }
    }

    if (stopRequested) {
        return;
    }
    count=0;
    lastUpdate=0;
    MusicLibraryItemRoot *library = new MusicLibraryItemRoot;
    QString topLevel=Utils::fixPath(QDir(folder).absolutePath());
    QSet<FileOnlySong> existing=existingSongs;
    scanFolder(library, topLevel, topLevel, existing, 0);

    if (!stopRequested) {
        library->applyGrouping();
        if (!cacheFile.isEmpty()) {
            writeProgress(0.0);
            library->toXML(cacheFile, QDateTime(), this);
        }
        emit libraryUpdated(library);
    } else {
        delete library;
    }
}
Beispiel #5
0
void MusicScanner::scan(const QString &folder, const QString &cacheFile, bool readCache, const QSet<FileOnlySong> &existingSongs)
{
    if (!cacheFile.isEmpty() && readCache) {
        MusicLibraryItemRoot *lib=new MusicLibraryItemRoot;
        readProgress(0.0);
        if (lib->fromXML(cacheFile, 0, 0, folder)) {
            if (!stopRequested) {
                emit libraryUpdated(lib);
            } else {
                delete lib;
            }
            return;
        } else {
            delete lib;
        }
    }

    if (stopRequested) {
        return;
    }
    count=0;
    MusicLibraryItemRoot *library = new MusicLibraryItemRoot;
    QString topLevel=Utils::fixPath(QDir(folder).absolutePath());
    QSet<FileOnlySong> existing=existingSongs;
    timer.start();
    scanFolder(library, topLevel, topLevel, existing, 0);

    if (!stopRequested) {
        if (!cacheFile.isEmpty()) {
            writeProgress(0.0);
            library->toXML(cacheFile, 0, false, this);
        }
        emit libraryUpdated(library);
    } else {
        delete library;
    }
}
Beispiel #6
0
void MusicScanner::saveCache(const QString &cache, MusicLibraryItemRoot *lib)
{
    writeProgress(0.0);
    lib->toXML(cache, 0, false, this);
    emit cacheSaved();
}