Пример #1
0
void DirectoryMangaVolume::readImages(const QString & path) {
    QFileInfo fileInfo(path);
    if (fileInfo.isDir()) {
        QDir dir(path);
        QStringList fileList = dir.entryList(
                    QDir::AllEntries | QDir::NoDotAndDotDot
                    | QDir::NoSymLinks | QDir::Hidden, QDir::Name
                    | QDir::IgnoreCase);
        for (int i = 0; i < fileList.count(); ++i) {
            readImages(path + tr("/")+fileList.at(i));
        }
    } else {
        QString extension = path.split(".").last();
        auto formats = Configuration().getSupportedImageFormats();
        if (Configuration().isSupportedImageFormat(fileInfo.suffix())) {
            m_page_names.push_back(fileInfo.canonicalFilePath());
            /*
            MangaPage img(path);
            if (!img.isNull()) {
                m_pages.push_back(img);
            }*/
        } else {
            qDebug() << "Skipping file with unknown extension " << path;
        }
    }
}
ImageInfo::ImageInfo(const std::string& _filename) : filename(_filename)
{
    name = Format(filename);
    readImages(&images, filename);
    width = images[0].columns();
    height = images[0].rows();
    thumbnail = MagickToBitmap(images[0], THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT);
}
Пример #3
0
void CompressedFileMangaVolume::extractToDir() {
//    QString program = "";
//    QStringList arguments;
//    setProgramAndArguments(filepath,m_file_dir,program,arguments);


    QProcess * myProcess = new QProcess(this);

    // Start the extraction program
    myProcess->start(m_programName, m_programArguments);

    // Check to make sure it started correctly
    if (!myProcess->waitForStarted()) {
        switch (myProcess->error()) {
        case QProcess::FailedToStart:
            qWarning() << "Failed to start program" << m_programName<< ". Is it installed correctly?";
            break;
        case QProcess::Crashed:
            qWarning() << "Program" << m_programName << "crashed.";
            break;
        default:
            qWarning() << "QProcess::ProcessError code " << myProcess->error();
        }
        return;
    }

    // Check to make sure it finished correctly
    if (!myProcess->waitForFinished()) {
        qWarning() << m_programName << "was unable to complete with arguments" << m_programArguments;
        // TODO(umbrant): capture stdout/stderr to show the user
        return;
    }

    // Successful extraction
    qWarning() << "Extracted successfully";
    m_do_cleanup = true;
    readImages(m_file_dir);
    for (const MangaPage& page: m_pages) {
        page.getFilename().size();
        // TODO(mtao): processing?
    }

}
Пример #4
0
/*
  main()
*/
int
main(int argc, char *argv[])
{
  Arguments args;
  int numImages, numSubjects;
  ImageList *srt;
  Matrix images;
  Subspace subspace;
    
  process_command(argc, argv, &args);

  MESSAGE(OPENING);
  MESSAGE(VERSION);

  /* The Matrix images is contains what is commonly calld the data matrix. It
     consists of n images, one image per column. Hence, each images data is 
     contiguous in memory. This choice facilities easy integration with the 
     Eigensolver used below */

  MESSAGE1ARG("Reading images from files in directory %s.", args.imageDirectory);

  images = readImages(args.imageList, args.imageDirectory, &args.vecLength,
		      &numImages, &numSubjects, &srt);
  
  subspaceTrain (&subspace, images, srt, numSubjects, args.dropNVectors, args.cutOffMode, args.cutOff, args.uselda, args.writeTextInterm);

  /* Write out text files for basis and values */
  if (args.writeTextBasis)
    {
      SAVE_MATRIX (subspace.basis);
      SAVE_MATRIX (subspace.mean);
      
      SAVE_MATRIX (subspace.values);
    }

  writeSubspace (&subspace, args.training_filename, args.imageList, args.argc, args.argv);
  
  MESSAGE("Finished Training.");
  
  return 0;
}
Пример #5
0
DirectoryMangaVolume::DirectoryMangaVolume(const QString & dirpath, QObject *parent, int prefetch_width)
    : MangaVolume(false, parent), m_prefetch_width(prefetch_width), m_num_renderwidgets(1) {
    readImages(dirpath);
}
Пример #6
0
CompressedFileMangaVolume::CompressedFileMangaVolume(const QString & filepath, QObject *parent, bool do_cleanup)
    : DirectoryMangaVolume(parent), m_do_cleanup(do_cleanup) {
    QStringList path_split = filepath.split("/");
    QString filename = path_split.last();
    QStringList filename_split = filename.split(".");
    if (filename_split.length() > 1) {
        filename_split.pop_back();
    }

    QDir dir;
    do {
        // keep trying hashes until dir exists.
        // no one could have taken all hashes
        QTime time = QTime::currentTime();
        QString toHash = filepath+time.toString();
        qWarning() <<  toHash;
        QString hash = QString(QCryptographicHash::hash(
                                   toHash.toAscii(),
                                   QCryptographicHash::Sha1).toHex());
        m_file_dir = tr("/tmp/") + filename_split.join(tr("."))
                + tr("-") + hash;
        qWarning() << "Making directory: " << m_file_dir;
        dir = QDir(m_file_dir);
    } while (dir.exists());
    dir.mkpath(".");

    QString program = "";
    QStringList arguments;
    if (filename.endsWith(tr(".zip"))) {
        program = tr("unzip");
        arguments << tr("-d") << m_file_dir;
        arguments << filepath;
    } else if (filename.endsWith(tr(".rar"))) {
        program = tr("unrar");
        arguments << tr("x");
        arguments << filepath;
        arguments << m_file_dir;
    } else {
        qWarning() << "Unknown filetype for file " << filename;
        return;
    }

    qWarning() << "Open file?: " << filename;
    QProcess * myProcess = new QProcess(this);

    // Start the extraction program
    myProcess->start(program, arguments);

    // Check to make sure it started correctly
    if (!myProcess->waitForStarted()) {
        switch (myProcess->error()) {
        case QProcess::FailedToStart:
            qWarning() << "Failed to start program" << program << ". Is it installed correctly?";
            break;
        case QProcess::Crashed:
            qWarning() << "Program" << program << "crashed.";
            break;
        default:
            qWarning() << "QProcess::ProcessError code " << myProcess->error();
        }
        return;
    }

    // Check to make sure it finished correctly
    if (!myProcess->waitForFinished()) {
        qWarning() << program << "was unable to extract file " << filepath;
        // TODO(umbrant): capture stdout/stderr to show the user
        return;
    }

    // Successful extraction
    qWarning() << "Extracted successfully";
    m_do_cleanup = true;
    readImages(m_file_dir);
    for (const MangaPage& page: m_pages) {
        page.getFilename().size();
        // TODO(mtao): processing?
    }
}
Пример #7
0
vector<Mat> ImageReader::readTrainingImages(string directory) {
	
		return readImages(directory, ".jpg");

}
Пример #8
0
vector<Mat> ImageReader::readClassifiedImages(string directory) {
	
		return readImages(directory, "Y.png");

}
Пример #9
0
vector<Mat> ImageReader::readDepthImages(string directory) {
	
	return readImages(directory, "X.png");

}