/// restore local motion from file LocalMotion restoreLocalmotion(FILE* f){ LocalMotion lm; char c; if(fscanf(f,"(LM %i %i %i %i %i %lf %lf", &lm.v.x,&lm.v.y,&lm.f.x,&lm.f.y,&lm.f.size, &lm.contrast, &lm.match) != 7) { vs_log_error(modname, "Cannot parse localmotion!\n"); return null_localmotion(); } while((c=fgetc(f)) && c!=')' && c!=EOF); if(c==EOF){ vs_log_error(modname, "Cannot parse localmotion missing ')'!\n"); return null_localmotion(); } return lm; }
/** * cleanmean_localmotions: calulcates the cleaned mean of a vector * of local motions considering * * Parameters: * localmotions : vs_vector of local motions * Return value: * A localmotion with vec with x and y being the cleaned mean * (meaning upper and lower pentile are removed) of * all local motions. all other fields are 0. * Preconditions: * size of vector >0 * Side effects: * None */ LocalMotion cleanmean_localmotions(const LocalMotions* localmotions) { int len = vs_vector_size(localmotions); int i, cut = len / 5; int* xs = localmotions_getx(localmotions); int* ys = localmotions_gety(localmotions); LocalMotion m = null_localmotion(); m.v.x=0; m.v.y=0; qsort(xs,len, sizeof(int), cmp_int); for (i = cut; i < len - cut; i++){ // all but cutted m.v.x += xs[i]; } qsort(ys, len, sizeof(int), cmp_int); for (i = cut; i < len - cut; i++){ // all but cutted m.v.y += ys[i]; } vs_free(xs); vs_free(ys); m.v.x/=(len - (2.0 * cut)); m.v.y/=(len - (2.0 * cut)); return m; }