Пример #1
0
  void PipelineStabDetect::init(Magick::Image img) {
    width = img.columns();
    height = img.rows();

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

    if (vsMotionDetectInit(&md, &stabConf->mdConf, &fi) != VS_OK) {
      throw runtime_error("Initialization of Motion Detection failed, please report a BUG");
    }
    vsMotionDetectGetConfig(&stabConf->mdConf, &md);

    *verboseOutput << "Video stabilization settings (pass 1/2):" << endl;
    *verboseOutput << "     shakiness = " << stabConf->mdConf.shakiness << endl;
    *verboseOutput << "      accuracy = " << stabConf->mdConf.accuracy << endl;
    *verboseOutput << "      stepsize = " << stabConf->mdConf.stepSize << endl;
    *verboseOutput << "   mincontrast = " << stabConf->mdConf.contrastThreshold << endl;
    *verboseOutput << "        tripod = " << stabConf->mdConf.virtualTripod << endl;
    *verboseOutput << "          show = " << stabConf->mdConf.show << endl;
    *verboseOutput << "        result = " << stabConf->stabStateFile->fileName() << endl;


    //f = fopen(stabStateFile->fileName().toStdString(), "w");
    f = stabConf->openStabStateFile("w");
    if (vsPrepareFile(&md, f) != VS_OK) {
      throw runtime_error(QString("cannot write to transform file %1").arg(stabConf->stabStateFile->fileName()).toStdString());
    }

    initialized = true;
  }
Пример #2
0
int test_store_restore(TestData* testdata){
  VSMotionDetectConfig mdconf = vsMotionDetectGetDefaulfConfig("test_motionDetect");
  VSMotionDetect md;
  test_bool(vsMotionDetectInit(&md, &mdconf, &testdata->fi) == VS_OK);

  LocalMotions lms;
  int i;
  for(i=0; i<2; i++){
    test_bool(vsMotionDetection(&md, &lms,&testdata->frames[i])== VS_OK);
    if (i==0) vs_vector_del(&lms);
  }

  FILE* f = fopen("lmtest","w");
  vsStoreLocalmotions(f,&lms);
  fclose(f);
  f = fopen("lmtest","r");
  LocalMotions test = vsRestoreLocalmotions(f);
  fclose(f);
  vsStoreLocalmotions(stderr,&test);
  compare_localmotions(&lms,&test);
  fprintf(stderr,"\n** LM and LMS OKAY\n");

  f = fopen("lmstest","w");
  md.frameNum=1;
  vsPrepareFile(&md,f);
  vsWriteToFile(&md,f,&lms);
  md.frameNum=2;
  vsWriteToFile(&md,f,&test);
  fclose(f);

  f = fopen("lmstest","r");
  test_bool(vsReadFileVersion(f)==1);
  LocalMotions read1;
  test_bool(vsReadFromFile(f,&read1)==1);
  compare_localmotions(&lms,&read1);
  LocalMotions read2;
  test_bool(vsReadFromFile(f,&read2)==2);
  compare_localmotions(&test,&read2);
  fclose(f);
  fprintf(stderr,"** Reading file stepwise OKAY\n");
  vs_vector_del(&read1);
  vs_vector_del(&read2);
  vs_vector_del(&test);
  vs_vector_del(&lms);

  f = fopen("lmstest","r");
  VSManyLocalMotions mlms;
  test_bool(vsReadLocalMotionsFile(f,&mlms)==VS_OK);
  test_bool(vs_vector_size(&mlms)==2);
  fprintf(stderr,"** Entire file routine OKAY\n\n");

  for(i=0; i< vs_vector_size(&mlms); i++){
    if(VSMLMGet(&mlms,i))
      vs_vector_del(VSMLMGet(&mlms,i));
  }
  vs_vector_del(&mlms);

  return 1;
}
Пример #3
0
static void init_analyze_data( mlt_filter filter, mlt_frame frame, VSPixelFormat vs_format, int width, int height )
{
	mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
	vs_data* data = (vs_data*)filter->child;
	vs_analyze* analyze_data = (vs_analyze*)calloc( 1, sizeof(vs_analyze) );
	memset( analyze_data, 0, sizeof(vs_analyze) );

	// Initialize a VSMotionDetectConfig
	const char* filterName = mlt_properties_get( properties, "mlt_service" );
	VSMotionDetectConfig conf = vsMotionDetectGetDefaultConfig( filterName );
	conf.shakiness = mlt_properties_get_int( properties, "shakiness" );
	conf.accuracy = mlt_properties_get_int( properties, "accuracy" );
	conf.stepSize = mlt_properties_get_int( properties, "stepsize" );
	conf.contrastThreshold = mlt_properties_get_double( properties, "mincontrast" );
	conf.show = mlt_properties_get_int( properties, "show" );
	conf.virtualTripod = mlt_properties_get_int( properties, "tripod" );

	// Initialize a VSFrameInfo
	VSFrameInfo fi;
	vsFrameInfoInit( &fi, width, height, vs_format );

	// Initialize the saved VSMotionDetect
	vsMotionDetectInit( &analyze_data->md, &conf, &fi );

	// Initialize the file to save results to
	char* filename = mlt_properties_get( properties, "filename" );
	analyze_data->results = fopen( filename, "w" );
	if ( vsPrepareFile( &analyze_data->md, analyze_data->results ) != VS_OK )
	{
		mlt_log_error( MLT_FILTER_SERVICE(filter), "Can not write to results file: %s\n", filename );
		destory_analyze_data( analyze_data );
		data->analyze_data = NULL;
	}
	else
	{
		data->analyze_data = analyze_data;
	}
}