def yuvToRgb( yuv ): "take an yuv array [y,u,v] (0..255) and return it in [r,g,b] (0..255)" "Attended value:" "red: [255,0,0] => [0°=>0,255,255]" y, u, v = yuv; r = numeric.limitRange( int( 1.164*(y - 16) + 1.596*(v-128) ), 0, 255 ); g = numeric.limitRange( int( 1.164*(y - 16) - 0.813*(u-128) - 0.391*(v-128) ), 0, 255 ); b = numeric.limitRange( int(1.164*(y - 16) + 2.018*(u-128) ), 0, 255 ); return [ r, g, b];
def interpolatePosition( aPos1, aPos2, rRatio = 0.5 ): "create a position intermediary between two positions if rRatio is 0. => pos1, if at 1. => pos2" "rRatio in [0.,1.]" listPosResult = {}; rRatio = numeric.limitRange( rRatio, 0., 1. ); for k, v in aPos1.iteritems(): if( k in aPos2 ): listPosResult[k] = v * ( 1. - rRatio ) + aPos2[k] * rRatio; return listPosResult;
def interpolatePosition(aPos1, aPos2, rRatio=0.5): "create a position intermediary between two positions if rRatio is 0. => pos1, if at 1. => pos2" "rRatio in [0.,1.]" listPosResult = {} rRatio = numeric.limitRange(rRatio, 0., 1.) for k, v in aPos1.iteritems(): if (k in aPos2): listPosResult[k] = v * (1. - rRatio) + aPos2[k] * rRatio return listPosResult