int test_store_restore(TestData* testdata){ MotionDetect md; test_bool(initMotionDetect(&md, &testdata->fi, "test") == VS_OK); test_bool(configureMotionDetect(&md)== VS_OK); LocalMotions lms; int i; for(i=0; i<2; i++){ test_bool(motionDetection(&md, &lms,&testdata->frames[i])== VS_OK); if (i==0) vs_vector_del(&lms); } FILE* f = fopen("lmtest","w"); storeLocalmotions(f,&lms); fclose(f); f = fopen("lmtest","r"); LocalMotions test = restoreLocalmotions(f); fclose(f); storeLocalmotions(stderr,&test); compare_localmotions(&lms,&test); fprintf(stderr,"\n** LM and LMS OKAY\n"); f = fopen("lmstest","w"); md.frameNum=1; prepareFile(&md,f); writeToFile(&md,f,&lms); md.frameNum=2; writeToFile(&md,f,&test); fclose(f); f = fopen("lmstest","r"); test_bool(readFileVersion(f)==1); LocalMotions read1; test_bool(readFromFile(f,&read1)==1); compare_localmotions(&lms,&read1); LocalMotions read2; test_bool(readFromFile(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"); ManyLocalMotions mlms; test_bool(readLocalMotionsFile(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(MLMGet(&mlms,i)) vs_vector_del(MLMGet(&mlms,i)); } vs_vector_del(&mlms); return 1; }
static int deshake_filter_video(TCModuleInstance *self, vframe_list_t *frame) { DeshakeData *sd = NULL; TC_MODULE_SELF_CHECK(self, "filter_video"); TC_MODULE_SELF_CHECK(frame, "filter_video"); sd = self->userdata; MotionDetect* md = &(sd->md); TransformData* td = &(sd->td); LocalMotions localmotions; Transform motion; VSFrame vsFrame; fillFrameFromBuffer(&vsFrame,frame->video_buf, &td->fiSrc); if(motionDetection(md, &localmotions, &vsFrame)!= VS_OK){ tc_log_error(MOD_NAME, "motion detection failed"); return TC_ERROR; } if(writeToFile(md, sd->f, &localmotions) != VS_OK) motion = simpleMotionsToTransform(td, &localmotions); vs_vector_del(&localmotions); transformPrepare(td, &vsFrame, &vsFrame); Transform t = lowPassTransforms(td, &sd->avg, &motion); /* tc_log_error(MOD_NAME, "Trans: det: %f %f %f \n\t\t act: %f %f %f %f", */ /* motion.x, motion.y, motion.alpha, */ /* t.x, t.y, t.alpha, t.zoom); */ if (sd->vob->im_v_codec == CODEC_RGB) { transformRGB(td, t); } else if (sd->vob->im_v_codec == CODEC_YUV) { transformYUV(td, t); } else { tc_log_error(MOD_NAME, "unsupported Codec: %i\n", sd->vob->im_v_codec); return TC_ERROR; } transformFinish(td); return TC_OK; }