G’ Morning SO-
I’m trying to move some bounding boxes on a video. I’m at sort of a sticking point . If I’ve got a frame on a data file every 15 frames, then I have to create 14 frames in between each real one. Since it’s a tool (actually part of an ffmpeg plugin), it needs to work for any gap size.
I’ve written a function that takes the distance between two points, and how many frames it has to smoothly transition from the beginning point to ending point. What this function would ideally return is an array of how many pixels to shift from the preceding frame
For example if x at frame 1 was 50, and at frame 16 was 65, then I would have an array of all ones so that each frame would add one to the frame before. Here’s what I’ve got so far:
int* generateSequence(int difference, int numStep){
int* sequence = (int*)malloc(sizeof(int*)*numStep);
int i;
for(i=0; i<numStep; i++){
sequence[i] = 0;
}
while(difference > numStep){
for(i=0; i<numStep; i++){
sequence[i]++;
}
difference -= numStep;
}
I’m satisfied with this part, (which would add one to EACH frame in between for every multiple of the distance between the two over the number of frames in between).
But now I’m getting to the point where I would need to add one to SOME frames but not all. All I’ve got is these jury rigged algorithms that aren’t very portable for a tool that produces different frame distances…
double delta = difference/numStep;
if(delta >=.05 && delta< .20){
for(i=0; i<numStep; i+=6){
sequence[i]++;
}
}
Should I be using a modulus operator or maybe approaching it differently? Hard coding in what seem like arbitrary values doesn’t sit too well with me.
More generally, it sounds like you want to generate the “smoothest” series of
xintegers whose sum isy. (Smoothness is minimal average distance between elements in the series.)This can be achieved with the following algorithm.
An example implementation in python (sorry, not a c person) can be found below.
Example invocations: