Continuing to investigate template matching for the Chiromancer and feel some hope as the last couple of algorithms I've written are pretty good at finding significant features on the palm images, now I'm looking at establishing a significant difference between images, and this looks pretty useful, infact what I am going to use it in the next iteration:
minSAD = VALUE_MAX;The last bit enables a rectangle to be drawn around the best matched region.
// loop through the search image
for ( int x = 0; x <= S_rows - T_rows; x++ ) {
for ( int y = 0; y <= S_cols - T_cols; y++ ) {
SAD = 0.0;
// loop through the template image
for ( int i = 0; i < T_rows; i++ )
for ( int j = 0; j < T_cols; j++ ) {
pixel p_SearchIMG = S[x+i][y+j];
pixel p_TemplateIMG = T[i][j];
SAD += abs( p_SearchIMG.Grey - p_TemplateIMG.Grey );
}
}
// save the best found position
if ( minSAD > SAD ) {
minSAD = SAD;
// give me VALUE_MAX
position.bestRow = x;
position.bestCol = y;
position.bestSAD = SAD;
}
}
No comments:
Post a Comment