Ejemplo n.º 1
0
void AlbumCoverSearcher::ImageLoaded(quint64 id, const QImage& image) {
  if (!cover_loading_tasks_.contains(id)) return;
  QStandardItem* item = cover_loading_tasks_.take(id);

  if (cover_loading_tasks_.isEmpty()) ui_->busy->hide();

  if (image.isNull()) {
    model_->removeRow(item->row());
    return;
  }

  QIcon icon(QPixmap::fromImage(image));

  // Create a pixmap that's padded and exactly the right size for the icon.
  QImage scaled_image(image.scaled(ui_->covers->iconSize(), Qt::KeepAspectRatio,
                                   Qt::SmoothTransformation));

  QImage padded_image(ui_->covers->iconSize(),
                      QImage::Format_ARGB32_Premultiplied);
  padded_image.fill(0);

  QPainter p(&padded_image);
  p.drawImage((padded_image.width() - scaled_image.width()) / 2,
              (padded_image.height() - scaled_image.height()) / 2,
              scaled_image);
  p.end();

  icon.addPixmap(QPixmap::fromImage(padded_image));

  item->setData(true, Role_ImageFetchFinished);
  item->setData(image.width() * image.height(), Role_ImageDimensions);
  item->setData(image.size(), Role_ImageSize);
  item->setIcon(icon);
}
Ejemplo n.º 2
0
cv::Mat_<cv::Vec3d> normalize(cv::Mat_<cv::Vec3b> img, int lowerLimit, int &upperLimit)
{
	if (upperLimit < 0) upperLimit = max_entry<cv::Vec3b>(img);
	// TODO: verbosity test necessary!
	std::cout << "byte version upper: " << upperLimit << std::endl;
	cv::Mat_<cv::Vec3d> scaled_image(img.rows, img.cols);
//	*#Q#($% convert to does not work :((
//	img.convertTo(scaled_image, 1.0/(upperLimit-lowerLimit), -(1.0*lowerLimit)/(upperLimit-lowerLimit));
	for (int y = 0; y < img.rows; ++y) {
		for (int x = 0; x < img.cols; ++x) {
			for (int c = 0; c < 3; ++c) {
				scaled_image[y][x][c] = ((double)img[y][x][c]-lowerLimit) / (double)(upperLimit - lowerLimit);
			}
		}
	}

	return scaled_image;
}
Ejemplo n.º 3
0
cv::Mat_<cv::Vec3d> normalize(QImage *img, int lowerLimit, int &upperLimit)
{
	if (upperLimit < 0) upperLimit = max_entry(img);

	int rows = img->height();
	int cols = img->width();
	cv::Mat_<cv::Vec3d> scaled_image(rows, cols);
	double divisor = upperLimit - lowerLimit;
	double align0 = 1.0*lowerLimit / divisor;
	for (int y = 0; y < rows; ++y) {
		for (int x = 0; x < cols; ++x) {
			const QRgb point = img->pixel(x, y);
			scaled_image[y][x] = cv::Vec3d(
				qBlue(point)/divisor - align0,
				qGreen(point)/divisor - align0,
				qRed(point)/divisor - align0
			);
		}
	}
	cv::imwrite("/tmp/testme.png", scaled_image*255);
	return scaled_image;
}
Ejemplo n.º 4
0
void EnrollDialog::enrollWorkDone(uchar *compositeImage, uchar *templateImage, int width, int height)
{
  if (compositeImage == NULL) { return; }

  DEBUG("EnrollWorkDone!!!!!");

  uchar imagio[width][height];
  int count = 0;
  for (int i = 0; i < width; i++) {
    for (int j = 0; j < height; j++) {
      imagio[i][j] = compositeImage[count];
      count++;
    }
  }
  delete [] compositeImage;

  uchar templateio[2048];
  for (int i = 0; i < 2048; i++) {
    templateio[i] = templateImage[i];
  }
  delete [] templateImage;

  // Mostrando imagen en pantalla
  QVector<QRgb> colorTable;
  for (int i = 0; i < 256; i++) { colorTable.push_back(QColor(i, i, i).rgb()); };
  QImage image((uchar *) imagio, width, height, QImage::Format_Indexed8); // was incorrect
  image.setColorTable(colorTable);

  QImage scaled_image(image.scaled(240, 200, Qt::KeepAspectRatio));

  lblName->setVisible(false);
  grid->removeWidget(grid->itemAtPosition(0, 0)->widget());
  grid->removeWidget(grid->itemAtPosition(1, 0)->widget());
  grid->removeWidget(grid->itemAtPosition(2, 0)->widget());

  grid->addWidget(lblEmpresa, 0, 0, 1, 4, Qt::AlignCenter);
  grid->addWidget(lblMsgScreen2, 1, 0, 4, 4, Qt::AlignCenter);

  btnOk->setVisible(true);
  lblMsgScreen2->setPixmap(QPixmap::fromImage(scaled_image));
  lblEmpresa->setText(tr("Aceptar para enrolar"));

  update();
  qApp->processEvents();

  // Creando imagenes para llamada a servicio web
  biobase64* base64help = new biobase64();
  QByteArray templateArray((char*) &templateio[0]);
  QByteArray imageArray((char*) &imagio[0]);
  imgRawB64 = base64help->base64_encode((const uchar *) &imagio[0], (unsigned int) sizeof(imagio));
  template1 = base64help->base64_encode((const uchar *) &templateio[0], (unsigned int) sizeof(templateio));

  //convirtiendo la imagen a jpg
  QByteArray im;
  QBuffer bufferJpeg(&im);
  bufferJpeg.open(QIODevice::WriteOnly);
  if (!image.save(&bufferJpeg, "PNG")) {
    DEBUG("Error saving image to buffer");
  }
  bufferJpeg.close();

  int pimgsize = 0;
  pimgsize = bufferJpeg.data().length();
  DEBUG("jpg size: %d", pimgsize);
  unsigned char pimgaux[pimgsize];
  for(int e = 0;e < pimgsize; e++) { pimgaux[e]= (unsigned char) bufferJpeg.data().at(e); }

  imgbaseJpg64 = base64help->base64_encode(pimgaux, (unsigned int) sizeof(pimgaux));
  DEBUG("jpg size: %d", imgbaseJpg64.size());
}