diff --git a/ipcam-apps/CameraApp/Control/AutomaticCompensation.cpp b/ipcam-apps/CameraApp/Control/AutomaticCompensation.cpp index dde96d6..a18fa87 100755 --- a/ipcam-apps/CameraApp/Control/AutomaticCompensation.cpp +++ b/ipcam-apps/CameraApp/Control/AutomaticCompensation.cpp @@ -1,5 +1,6 @@ // // Author: Fionn Behrens, kernelconcepts +// Simon Budig, kernelconcepts // extern "C" { @@ -390,6 +391,22 @@ void AutomaticCompensation::DoNextFrame(GrabFrontend &grabber, CameraConfig &cfg } } + { + double avgU, avgV; + double varU, varV; + + avgU = ((double) stat.SumU) / (stat.NumPixel / 4); + avgV = ((double) stat.SumV) / (stat.NumPixel / 4); + varU = ((double) stat.Sum2U) / (stat.NumPixel / 4); + varV = ((double) stat.Sum2V) / (stat.NumPixel / 4); + + varU -= avgU * avgU; + varV -= avgV * avgV; + + // FIXME: immer noch unplausible Werte. Warum kommt da manchmal eine negative Varianz raus??? + fprintf (stderr, "avg: %7.3f, %7.3f -- varianz: %7.3f, %7.3f\n", avgU, avgV, varU, varV); + } + if (CameraConfig::IR_FILTER_AUTO == cfg.ImageControls.IRFilterMode) { if (thres > out.ir_open_thres && cfg.ImageControls.IRFilterState != CameraConfig::IR_FILTER_OPEN) { diff --git a/ipcam-apps/CameraApp/Control/FrameDispatcher.cpp b/ipcam-apps/CameraApp/Control/FrameDispatcher.cpp index 7e1b0bc..4e075ed 100755 --- a/ipcam-apps/CameraApp/Control/FrameDispatcher.cpp +++ b/ipcam-apps/CameraApp/Control/FrameDispatcher.cpp @@ -925,8 +925,36 @@ void FrameDispatcher::LoopFrames() { f->pGlobalStringTable = &GlobalStringTable; // Get statistics for this image (compensator is started later)... - Grabber.UpdateAnalogStatistics(stat, f->GetTimestamp(), 16, 240); + Grabber.UpdateAnalogStatistics (stat, f->GetTimestamp(), 16, 240); +#if 1 +#warning REMOVE Variance Calculation when implemented in the FPGA + { + PixelDimension dim; + unsigned char *data; + int i; + + data = f->GetPayload(); + dim = f->GetSize (); + + stat.SumU = 0; + stat.Sum2U = 0; + stat.SumV = 0; + stat.Sum2V = 0; + if (f->GetVideomode() == 0) { + for (i = 0; i < dim.Width * dim.Height / 4; i++) { + stat.SumU += data [dim.Width * dim.Height + i]; + stat.Sum2U += ((int) data [dim.Width * dim.Height + i]) * + data [dim.Width * dim.Height + i]; + } + for (i = 0; i < dim.Width * dim.Height / 4; i++) { + stat.SumV += data [dim.Width * dim.Height / 4 * 5 + i]; + stat.Sum2V += ((int) data [dim.Width * dim.Height / 4 * 5 + i]) * + data [dim.Width * dim.Height / 4 * 5 + i]; + } + } + } +#endif // Things we only do in normal mode if(CameraConfig::OM_NORMAL == loop_mode) { diff --git a/ipcam-apps/CameraApp/Grabber/AnalogStatistics.hpp b/ipcam-apps/CameraApp/Grabber/AnalogStatistics.hpp index 7ad4357..80fe31a 100755 --- a/ipcam-apps/CameraApp/Grabber/AnalogStatistics.hpp +++ b/ipcam-apps/CameraApp/Grabber/AnalogStatistics.hpp @@ -13,6 +13,10 @@ struct AnalogStatistics { unsigned int SumRed; ///< Sum of all red pixel unsigned int SumGreen; ///< Sum of all green pixel unsigned int SumBlue; ///< Sum of all blue pixel + unsigned int SumU; ///< Sum of all U values + unsigned long long Sum2U; ///< Sum of all U values^2 + unsigned int SumV; ///< Sum of all V values + unsigned long long Sum2V; ///< Sum of all V values^2 void print() { DEBUG(LEVEL_ALWAYS, "IMAGE-STATISTICS:\n");