Example #1
0
  void PipelineStabTransform::init(Magick::Image img) {
    width = img.columns();
    height = img.rows();


    if (!vsFrameInfoInit(&fi, width, height, PF_RGB24)) {
      throw runtime_error("Failed to initialize frame format");
    }
    fi.planes = 1; // I don't understand vs frame info... But later is assert for planes == 1

    if (vsTransformDataInit(&td, &stabConf->tsConf, &fi, &fi) != VS_OK) {
      throw runtime_error("initialization of vid.stab transform failed, please report a BUG");
    }
    vsTransformGetConfig(&stabConf->tsConf, &td);

    *verboseOutput << "Video transformation/stabilization settings (pass 2/2):" << endl;
    *verboseOutput << "    input     = " << stabConf->stabStateFile->fileName() << endl;
    *verboseOutput << "    smoothing = " << stabConf->tsConf.smoothing << endl;
    *verboseOutput << "    optalgo   = " <<
      (stabConf->tsConf.camPathAlgo == VSOptimalL1 ? "opt" :
      (stabConf->tsConf.camPathAlgo == VSGaussian ? "gauss" : "avg")) << endl;
    *verboseOutput << "    maxshift  = " << stabConf->tsConf.maxShift << endl;
    *verboseOutput << "    maxangle  = " << stabConf->tsConf.maxAngle << endl;
    *verboseOutput << "    crop      = " << (stabConf->tsConf.crop ? "Black" : "Keep") << endl;
    *verboseOutput << "    relative  = " << (stabConf->tsConf.relative ? "True" : "False") << endl;
    *verboseOutput << "    invert    = " << (stabConf->tsConf.invert ? "True" : "False") << endl;
    *verboseOutput << "    zoom      = " << (stabConf->tsConf.zoom) << endl;
    *verboseOutput << "    optzoom   = " << (
      stabConf->tsConf.optZoom == 1 ? "Static (1)" : (stabConf->tsConf.optZoom == 2 ? "Dynamic (2)" : "Off (0)")) << endl;
    if (stabConf->tsConf.optZoom == 2)
      *verboseOutput << "    zoomspeed = " << stabConf->tsConf.zoomSpeed << endl;
    *verboseOutput << "    interpol  = " << getInterpolationTypeName(stabConf->tsConf.interpolType) << endl;

    //f = fopen(stabStateFile->fileName().toStdString(), "r");
    f = stabConf->openStabStateFile("r");
    VSManyLocalMotions mlms;
    if (vsReadLocalMotionsFile(f, &mlms) == VS_OK) {
      // calculate the actual transforms from the local motions
      if (vsLocalmotions2Transforms(&td, &mlms, &trans) != VS_OK) {
        throw runtime_error("calculating transformations failed");
      }
    } else { // try to read old format
      if (!vsReadOldTransforms(&td, f, &trans)) { /* read input file */
        throw runtime_error(QString("error parsing input file %1").arg(stabConf->stabStateFile->fileName()).toStdString());
      }
    }

    fclose(f);
    f = NULL;

    if (vsPreprocessTransforms(&td, &trans) != VS_OK) {
      throw runtime_error("error while preprocessing transforms");
    }
    initialized = true;
  }
Example #2
0
/**
 * transform_configure:  Configure this instance of the module.  See
 * tcmodule-data.h for function details.
 */
static int transform_configure(TCModuleInstance *self,
             const char *options, vob_t *vob)
{
    FilterData *fd = NULL;
    char* filenamecopy, *filebasename;
    FILE* f;
    TC_MODULE_SELF_CHECK(self, "configure");

    fd = self->userdata;
    VSTransformData* td = &(fd->td);

    fd->vob = vob;
    if (!fd->vob)
        return TC_ERROR; /* cannot happen */

    /**** Initialise private data structure */

    VSFrameInfo fi_src;
    VSFrameInfo fi_dest;
    vsFrameInfoInit(&fi_src, fd->vob->ex_v_width, fd->vob->ex_v_height,
                  transcode2ourPF(fd->vob->im_v_codec));
    vsFrameInfoInit(&fi_dest, fd->vob->ex_v_width, fd->vob->ex_v_height,
                  transcode2ourPF(fd->vob->im_v_codec));

    VSTransformConfig conf = vsTransformGetDefaultConfig(MOD_NAME);
    conf.verbose = verbose;
    fd->sharpen  = 0.8;


    vsTransformationsInit(&fd->trans);

    filenamecopy = tc_strdup(fd->vob->video_in_file);
    filebasename = basename(filenamecopy);
    if (strlen(filebasename) < TC_BUF_LINE - 4) {
        tc_snprintf(fd->input, TC_BUF_LINE, "%s.trf", filebasename);
    } else {
        tc_log_warn(MOD_NAME, "input name too long, using default `%s'",
                    DEFAULT_TRANS_FILE_NAME);
        tc_snprintf(fd->input, TC_BUF_LINE, DEFAULT_TRANS_FILE_NAME);
    }



    /* process remaining options */
    if (options != NULL) {
        // We support also the help option.
        if(optstr_lookup(options, "help")) {
            tc_log_info(MOD_NAME,vs_transform_help);
            return(TC_IMPORT_ERROR);
        }
        optstr_get(options, "input",  "%[^:]", (char*)&fd->input);
        optstr_get(options, "maxshift",  "%d", &conf.maxShift);
        optstr_get(options, "maxangle", "%lf", &conf.maxAngle);
        optstr_get(options, "smoothing", "%d", &conf.smoothing);
        optstr_get(options, "invert"   , "%d", &conf.invert);
        optstr_get(options, "relative" , "%d", &conf.relative);
        optstr_get(options, "zoom"     ,"%lf", &conf.zoom);
        optstr_get(options, "optzoom"  , "%d", &conf.optZoom);
        optstr_get(options, "zoomspeed", "%lf",&conf.zoomSpeed);
        optstr_get(options, "interpol" , "%d", (int*)(&conf.interpolType));
        optstr_get(options, "sharpen"  ,"%lf", &fd->sharpen);
        if(optstr_lookup(options, "tripod")){
            tc_log_info(MOD_NAME,"Virtual tripod mode: relative=False, smoothing=0");
            conf.relative=0;
            conf.smoothing=0;
        }
    }

    if(vsTransformDataInit(td, &conf, &fi_src, &fi_dest) != VS_OK){
        tc_log_error(MOD_NAME, "initialization of VSTransformData failed");
        return TC_ERROR;
    }
    vsTransformGetConfig(&conf,td);

    if (verbose) {
        tc_log_info(MOD_NAME, "Image Transformation/Stabilization Settings:");
        tc_log_info(MOD_NAME, "    input     = %s", fd->input);
        tc_log_info(MOD_NAME, "    smoothing = %d", conf.smoothing);
        tc_log_info(MOD_NAME, "    maxshift  = %d", conf.maxShift);
        tc_log_info(MOD_NAME, "    maxangle  = %f", conf.maxAngle);
        tc_log_info(MOD_NAME, "    crop      = %s",
                        conf.crop ? "Black" : "Keep");
        tc_log_info(MOD_NAME, "    relative  = %s",
                    conf.relative ? "True": "False");
        tc_log_info(MOD_NAME, "    invert    = %s",
                    conf.invert ? "True" : "False");
        tc_log_info(MOD_NAME, "    zoom      = %f", conf.zoom);
        tc_log_info(MOD_NAME, "    optzoom   = %d", conf.optZoom);
        if(conf.optZoom==2){
            tc_log_info(MOD_NAME, "    zoomspeed = %f", conf.zoomSpeed);
        }
        tc_log_info(MOD_NAME, "    interpol  = %s",
                    getInterpolationTypeName(conf.interpolType));
        tc_log_info(MOD_NAME, "    sharpen   = %f", fd->sharpen);
    }

    f = fopen(fd->input, "r");
    if (f == NULL) {
        tc_log_error(MOD_NAME, "cannot open input file %s!\n", fd->input);
        /* return (-1); when called using tcmodinfo this will fail */
    } else {
        VSManyLocalMotions mlms;
        if(vsReadLocalMotionsFile(f,&mlms)==VS_OK){
            // calculate the actual transforms from the localmotions
            if(vsLocalmotions2Transforms(td, &mlms,&fd->trans)!=VS_OK)
                tc_log_error(MOD_NAME, "calculating transformations failed!\n");
        }else{ // try to read old format
            if (!vsReadOldTransforms(td, f, &fd->trans)) { /* read input file */
                tc_log_error(MOD_NAME, "error parsing input file %s!\n", fd->input);
            }
        }
    }
    fclose(f);

    if (vsPreprocessTransforms(td, &fd->trans)!= VS_OK ) {
        tc_log_error(MOD_NAME, "error while preprocessing transforms!");
        return TC_ERROR;
    }

    // sharpen is still in transcode...
    /* Is this the right point to add the filter? Seems to be the case.*/
    if(fd->sharpen>0){
        /* load unsharp filter */
        char unsharp_param[256];
        sprintf(unsharp_param,"luma=%f:%s:chroma=%f:%s",
                fd->sharpen, "luma_matrix=5x5",
                fd->sharpen/2, "chroma_matrix=5x5");
        if (!tc_filter_add("unsharp", unsharp_param)) {
            tc_log_warn(MOD_NAME, "cannot load unsharp filter!");
        }
    }

    return TC_OK;
}
void gpuNUFFT::TextureGpuNUFFTOperator::freeLookupTable()
{
  if (kernel_d != NULL)
    freeTexture(getInterpolationTypeName(), kernel_d);
}
void gpuNUFFT::TextureGpuNUFFTOperator::initLookupTable()
{
  initTexture(getInterpolationTypeName(), &kernel_d, this->kernel);
}