char* lm_serializer(LocalMotions *lms, int length) { std::ostringstream oss; int size = vs_vector_size(lms); for (int i = 0; i < size; ++i) { LocalMotion* lm = (LocalMotion*) vs_vector_get(lms, i); oss << lm->v.x << ' '; oss << lm->v.y << ' '; oss << lm->f.x << ' '; oss << lm->f.y << ' '; oss << lm->f.size << ' '; oss << lm->contrast << ' '; oss << lm->match << ' '; } return strdup(oss.str().c_str()); }
static void init_apply_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_apply* apply_data = (vs_apply*)calloc( 1, sizeof(vs_apply) ); char* filename = mlt_properties_get( properties, "results" ); memset( apply_data, 0, sizeof( vs_apply ) ); mlt_log_info( MLT_FILTER_SERVICE(filter), "Load results from %s\n", filename ); // Initialize the VSTransformConfig get_transform_config( &apply_data->conf, filter, frame ); // Initialize VSTransformData VSFrameInfo fi_src, fi_dst; vsFrameInfoInit( &fi_src, width, height, vs_format ); vsFrameInfoInit( &fi_dst, width, height, vs_format ); vsTransformDataInit( &apply_data->td, &apply_data->conf, &fi_src, &fi_dst ); // Initialize VSTransformations vsTransformationsInit( &apply_data->trans ); // Convert file name string encoding. mlt_properties_from_utf8( properties, "results", "_results" ); filename = mlt_properties_get( properties, "_results" ); // Load the motions from the analyze step and convert them to VSTransformations FILE* f = fopen( filename, "r" ); VSManyLocalMotions mlms; if( vsReadLocalMotionsFile( f, &mlms ) == VS_OK ) { int i = 0; mlt_log_info( MLT_FILTER_SERVICE(filter), "Successfully loaded %d motions\n", vs_vector_size( &mlms ) ); vsLocalmotions2Transforms( &apply_data->td, &mlms, &apply_data->trans ); vsPreprocessTransforms( &apply_data->td, &apply_data->trans ); // Free the MultipleLocalMotions for( i = 0; i < vs_vector_size( &mlms ); i++ ) { LocalMotions* lms = (LocalMotions*)vs_vector_get( &mlms, i ); if( lms ) { vs_vector_del( lms ); } } vs_vector_del( &mlms ); data->apply_data = apply_data; } else { mlt_log_error( MLT_FILTER_SERVICE(filter), "Can not read results file: %s\n", filename ); destory_apply_data( apply_data ); data->apply_data = NULL; } if( f ) { fclose( f ); } }