void MainWindow::browseSampleImages() { QString dirPath = QFileDialog::getExistingDirectory(this, tr("Open sample file"), QDir::homePath()); if (!dirPath.isEmpty()) { sampleImagePath = dirPath; for(int i = 0; i < CLASS_AMOUNT; i++) { QDir imagesDir(dirPath); QStringList filters; filters << QString("%1.*.png").arg(i); imagesDir.setNameFilters(filters); QStringList list = imagesDir.entryList(); if (list.count() < SAMPLES_PER_CLASS) { QMessageBox::information(this, tr("Error"), tr("Not enough images in this directory")); sampleImagePath = ""; return; } for (int j = i * SAMPLES_PER_CLASS; j < i * SAMPLES_PER_CLASS + SAMPLES_PER_CLASS; j++) { QString path = dirPath + "/" + list.takeFirst(); if (!sampleImages[j].load(path)) { QMessageBox::information(this, tr("Error"), tr("Failed loading %1").arg(path)); sampleImagePath = ""; return; } imageLabels[j]->setPixmap(QPixmap::fromImage(sampleImages[j].scaled(50, 50))); } } if (!testImagePath.isEmpty()) { ui->recognizeButton->setEnabled(true); } QList<QImage> allImages; for(int i = 0; i < SAMPLE_AMOUNT; i++) { allImages.append(sampleImages[i]); } // Teach network ONLY ONECE to recognize THIS selection! cn.setParameters(IMAGE_SIZE, CLASS_AMOUNT); cn.teach(allImages); } }
static void PopulateWithImages(QListWidget * const imagelist, const QString &path) { QDir imagesDir(path); QStringList extensions; extensions << "*.jpg" << "*.png" << "*.bmp" << "*.gif"; const QFileInfoList fileList = imagesDir.entryInfoList(extensions, QDir::Files, QDir::Name | QDir::IgnoreCase); for (QFileInfoList::const_iterator it = fileList.begin(); it != fileList.end(); ++it) { QListWidgetItem * const item = new QListWidgetItem(QIcon(QPixmap(it->absoluteFilePath())), it->fileName()); imagelist->addItem(item); } }