I have been working on trying to visualize the motion vectors including their location and direction as displayed in an RGB buffer by modifying the buffer to draw pixels in the patterns of arrows going towards 8 directions. For some reason, I am only seeing arrows that are directed eastward or southeast ward or southward. This to me indicates that the x_vector and y_vector are only positive values. I assumed that x_vector that is positive means macroblock motion to the Right and y_vector positive means macroblock motion downward. Maybe somebody can take a look at a code snippet or explain what I should be seeing in the macroblock x_vector and y_vector.
The code snippets here are based on the assumption of motion vector struct as having the following design. I have seen in other posts that it lists the sad before the x_vector and y_vector.
Code: Select all
struct mmal_motion_vector {
char x_vector;
char y_vector;
short sad;
};
Code: Select all
for (int j=0;j < numblocks ; j++) {
uint8_t block_direction=0;
//[nw][w][sw][s][se][e][ne][n]
//[0] [1][2] [3][4] [5][6] [7]
//[n][ne][e][se][s][sw][w][nw]
//[7][6] [5][4] [3][2] [1][0]
mmal_motion_vector *mvarray=(mmal_motion_vector *)buffer->data;
(....)
if ((abs(mvarray[j].x_vector) + abs(mvarray[j].y_vector)) > min_vector_distance) {
registers = registers | (0x80000000 >> count);
/* N */ if (mvarray[j].x_vector >0) { //to e
if (mvarray[j].y_vector >0) { //to se
/* W E */ block_direction |= 1<<4;
} else if (mvarray[j].y_vector <0) { //to ne
/* S */ block_direction |= 1<<6;
} else { //e
block_direction |= 1<<5;
}
} else if (mvarray[j].x_vector <0) { //to w
if (mvarray[j].y_vector >0) { //to sw
block_direction |= 1<<2;
} else if (mvarray[j].y_vector <0) { //to nw
block_direction |= 1<<0;
} else { //w
block_direction |= 1<<1;
}
} else { //dx=0
if (mvarray[j].y_vector >0) { //to s
block_direction |= 1<<3;
} else if (mvarray[j].y_vector <0) { //to n
block_direction |= 1<<7;
} else { //dy=0
}
}
//each Block save to the zones direction buffer on the jth position
memcpy(direction[i]+j,&block_direction,sizeof(block_direction));
}
Also, what would be a recommended value for SAD to determine if this macroblock should be considered for motion scoring?
Thanks,
Chris
