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; }
int main(int argc, char *argv[]) { VSFrameInfo fi; VSMotionDetect md; VSMotionDetectConfig conf; (void)argc; (void)argv; conf.algo = 1; conf.modName = "vidstabtest"; conf.shakiness = 5; conf.accuracy = 15; conf.stepSize = 6; conf.contrastThreshold = 0.25; conf.show = 0; conf.virtualTripod = 0; vsFrameInfoInit(&fi, 320, 240, PF_YUV420P); if (vsMotionDetectInit(&md, &conf, &fi) != VS_OK) return 1; vsMotionDetectionCleanup(&md); return 0; }
static StabData* init_detect(mlt_properties properties, mlt_image_format *format, int *width, int *height) { StabData *data = new StabData; memset(data, 0, sizeof(StabData)); data->animation = mlt_animation_new(); VSPixelFormat pf = convertImageFormat(*format); VSFrameInfo fi; vsFrameInfoInit(&fi, *width, *height, pf); 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.algo = mlt_properties_get_int(properties, "algo"); conf.contrastThreshold = mlt_properties_get_double(properties, "mincontrast"); conf.show = mlt_properties_get_int(properties, "show"); conf.virtualTripod = mlt_properties_get_int(properties, "tripod"); vsMotionDetectInit(&data->md, &conf, &fi); // add vectors to properties mlt_properties_set_data(properties, "vectors", data->animation, 1, (mlt_destructor) mlt_animation_close, (mlt_serialiser) vectors_serializer); return data; }
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; }
void test_checkCompareImg(const TestData* testdata){ VSMotionDetect md; VSMotionDetectConfig conf = vsMotionDetectGetDefaultConfig("test_checkCompareImg"); conf.shakiness=6; conf.accuracy=12; test_bool(vsMotionDetectInit(&md, &conf, &testdata->fi) == VS_OK); fflush(stdout); test_bool(checkCompareImg(&md,&testdata->frames[0])); vsMotionDetectionCleanup(&md); }
int init_deshake(DeshakeData *data, mlt_properties properties, mlt_image_format *format, int *width, int *height, char* interps) { VSPixelFormat pf = convertImageFormat(*format); VSFrameInfo fiIn, fiOut; vsFrameInfoInit(&fiIn, *width, *height, pf); vsFrameInfoInit(&fiOut, *width, *height, pf); VSMotionDetectConfig conf = vsMotionDetectGetDefaultConfig(FILTER_NAME); 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.algo = mlt_properties_get_int(properties, "algo"); conf.contrastThreshold = mlt_properties_get_double(properties, "mincontrast"); conf.show = 0; vsMotionDetectInit(&data->md, &conf, &fiIn); VSTransformConfig tdconf = vsTransformGetDefaultConfig(FILTER_NAME); tdconf.smoothing = mlt_properties_get_int(properties, "smoothing"); tdconf.maxShift = mlt_properties_get_int(properties, "maxshift"); tdconf.maxAngle = mlt_properties_get_double(properties, "maxangle"); tdconf.crop = (VSBorderType) mlt_properties_get_int(properties, "crop"); tdconf.zoom = mlt_properties_get_int(properties, "zoom"); tdconf.optZoom = mlt_properties_get_int(properties, "optzoom"); tdconf.zoomSpeed = mlt_properties_get_double(properties, "zoomspeed"); tdconf.relative = 1; tdconf.invert = 0; // by default a bilinear interpolation is selected tdconf.interpolType = VS_BiLinear; if (strcmp(interps, "nearest") == 0 || strcmp(interps, "neighbor") == 0) tdconf.interpolType = VS_Zero; else if (strcmp(interps, "tiles") == 0 || strcmp(interps, "fast_bilinear") == 0) tdconf.interpolType = VS_Linear; vsTransformDataInit(&data->td, &tdconf, &fiIn, &fiOut); data->avg.initialized = 0; return 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; } }