Bonjour v3as4k,
here is the formulas I used in motion detection. In fact, only 5742 replace 5743 in the original code and I commented where these values are comming from.
switch( motion_detector->pixel_measure_mode )
{
case MD_MEASURE_MODE_U: val = cb; break;
case MD_MEASURE_MODE_V: val = cr; break;
yc = val << 12;
cb = ( cb > 127 ? cb - 256 : cb ); // Cb value
cr = ( cr > 127 ? cr - 256 : cr ); // Cr value
case MD_MEASURE_MODE_R: val = clip ( ( yc + ( 5742 * cr ) + 2048 ) >> 12 ); break;
case MD_MEASURE_MODE_G: val = clip ( ( yc - ( 1410 * cb + 2925 * cr ) + 2048 ) >> 12 ); break;
case MD_MEASURE_MODE_B: val = clip ( ( yc + ( 7258 * cb ) + 2048 ) >> 12 ); break;
default : val = yc; break;
}
; // end of switch
/*
Lebeau : also http://en.wikipedia.org/wiki/YCbCr
upon TIFF-EP specs
R = Cr * ( 2 - 2 * LumaRed ) + Y = Y + 2 * Cr * ( 1 - LumaRed )
G = ( Y - LumaBlue * B - LumaRed * R ) / LumaGreen = ( Y - ( B*LumaBlue + R*LumaRed ) ) / LumaGreen
B = Cb * ( 2 - 2 * LumaBlue ) + Y = Y + 2 * Cb * ( 1 - LumaBlue )
The values coded by this field will typically reflect the transformation specified by a standard for YCbCr encoding.
The following table contains examples of commonly used values.
Standard LumaRed LumaGreen LumaBlue
CCIR Recommendation 601-1 299 / 1000 587 / 1000 114 / 1000
CCIR Recommendation 709 2125 / 10000 7154 / 10000 721 / 10000
Motion Detection 601-1 based 1225 / 4096 2404 / 4096 467 / 4096
#define LUMA_RED 1225
#define LUMA_RED_COEF1 5742 // 2 * ( 1 - luma_red )
#define LUMA_RED_COEF2 2925 // 2 * ( luma_red - luma_red2 ) / luma_green
#define LUMA_GREEN 2404
#define LUMA_BLUE 467
#define LUMA_BLUE_COEF1 7258 // 2 * ( 1 - luma_blue )
#define LUMA_BLUE_COEF2 1410 // 2 * ( luma_blue - luma_blue2 ) / luma_green
#define HALF_SCALE 2048 // 4096 / 2
*/
When you are detecting motion in R, G or B from the viewport, these values are well computed but your point is probably regarding the volatily of the accuracy of the viewport.
The viewport has the property, within the limit of my knowledge, to automaticaly adjust the luminance and the white balance (on my A650, I am sure) and therefore could impair the precision of some chromas since the viewport could adjust his display upon the object in motion and consequently indicates motion all over the targetted area. Humm.
In my motion detection code, I submitted to CHDK (
http://chdk.setepontos.com/index.php?topic=650.msg61021#msg61021), I integrated "wait-stability" (parameters = 16) which wait for some viewport stability (after msecs before trigger expired) to be sure viewport will be stable before starting to check for motion.
P.S.: Tabarouette ewavr, you're right. How a compiler miss that ? I will fix it in my sbmitted code !!!