Ejemplo n.º 1
0
static TransformationMatrix applyTransformAnimation(const TransformOperations& from, const TransformOperations& to, double progress, const FloatSize& boxSize, bool listsMatch)
{
    TransformationMatrix matrix;

    // First frame of an animation.
    if (!progress) {
        from.apply(boxSize, matrix);
        return matrix;
    }

    // Last frame of an animation.
    if (progress == 1) {
        to.apply(boxSize, matrix);
        return matrix;
    }

    // If we have incompatible operation lists, we blend the resulting matrices.
    if (!listsMatch) {
        TransformationMatrix fromMatrix;
        to.apply(boxSize, matrix);
        from.apply(boxSize, fromMatrix);
        matrix.blend(fromMatrix, progress);
        return matrix;
    }

    // Animation to "-webkit-transform: none".
    if (!to.size()) {
        TransformOperations blended(from);
        for (auto& operation : blended.operations())
            operation->blend(nullptr, progress, true)->apply(matrix, boxSize);
        return matrix;
    }

    // Animation from "-webkit-transform: none".
    if (!from.size()) {
        TransformOperations blended(to);
        for (auto& operation : blended.operations())
            operation->blend(nullptr, 1 - progress, true)->apply(matrix, boxSize);
        return matrix;
    }

    // Normal animation with a matching operation list.
    TransformOperations blended(to);
    for (size_t i = 0; i < blended.operations().size(); ++i)
        blended.operations()[i]->blend(from.at(i), progress, !from.at(i))->apply(matrix, boxSize);
    return matrix;
}
Ejemplo n.º 2
0
bool stitch(Options opts, StitchProgressCallable* callback)
{
  try
  {

    StitchEngine stitcher(opts);

    int i = 0;
    int t_s = opts.image_names.size();
    while (opts.image_names.size())
    {
      string imagename = opts.image_names.back();
      string imagename_full = opts.directory + "/" + imagename;
      std::cout << "reading " << imagename_full << std::endl;

      Mat img = imread(opts.directory + "/" + imagename);
      if(img.empty()){
        std::cerr << "image was not read!" << std::endl;
      }
      stitcher.addNewImage(img);

      if (callback)
      {
        callback->onProgress(int((float(i++) / t_s) * 100));
      }
      opts.image_names.pop_back();
    }
    Mat blended(opts.stitch_size,CV_8UC3);
    stitcher.stitch(blended,callback);

    vector<int> write_params(2);
    write_params[0] = CV_IMWRITE_JPEG_QUALITY;
    write_params[1] = 85; //need low size for emailing


    imwrite(opts.stitch_output, blended, write_params);
  }
  catch (CanceledException e)
  {
    std::cout << ("Canceled");
    return true;
  }
  catch (...)
  {
    std::cerr << ("Fail stitch!");
    return false;
  }
  return true;

}