1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* @file HistogramProvider.h
*
* @author <a href="mailto:mellmann@informatik.hu-berlin.de">Heinrich Mellmann</a>
* Declaration of class HistogramProvider
*/

#ifndef _HistogramProvider_h_
#define _HistogramProvider_h_

#include <ModuleFramework/Module.h>

// Representations
#include "Representations/Infrastructure/Image.h"
#include "Representations/Perception/Histograms.h"
#include "Representations/Perception/BodyContour.h"

#include "Tools/DoubleCamHelpers.h"
#include "Tools/DataStructures/UniformGrid.h"

// Debug
#include "Tools/Debug/DebugRequest.h"
#include "Tools/Debug/DebugPlot.h"

//////////////////// BEGIN MODULE INTERFACE DECLARATION ////////////////////

BEGIN_DECLARE_MODULE(HistogramProvider)
  PROVIDE(DebugRequest)
  PROVIDE(DebugPlot)

  REQUIRE(Image)
  REQUIRE(ImageTop)
  REQUIRE(BodyContour)
  REQUIRE(BodyContourTop)

  PROVIDE(ColorChannelHistograms)
  PROVIDE(ColorChannelHistogramsTop)
END_DECLARE_MODULE(HistogramProvider)

//////////////////// END MODULE INTERFACE DECLARATION //////////////////////

class HistogramProvider : public HistogramProviderBase
{
public:

  HistogramProvider();
  ~HistogramProvider(){}

  /** executes the module */
  virtual void execute(CameraInfo::CameraID id);

  void execute()
  {
    execute(CameraInfo::Bottom);
    execute(CameraInfo::Top);

    //reset camera ID to Bottom for debug
    cameraID = CameraInfo::Bottom;
    showDebugInfos();
  }

  void showDebugInfos() const;

private:
  CameraInfo::CameraID cameraID;
  UniformGrid uniformGrid; // subsampling of the image

  DOUBLE_CAM_REQUIRE(HistogramProvider, Image);
  DOUBLE_CAM_REQUIRE(HistogramProvider, BodyContour);

  DOUBLE_CAM_PROVIDE(HistogramProvider, ColorChannelHistograms);

  //generate plot for raw, normalized and cumulated histograms
  void plot(std::string id, Statistics::HistogramX& histogram) const
  {
    for(int i = 0; i < histogram.size; i++)
    {
      PLOT_GENERIC(id + ":rawHistogram", i, histogram.rawData[i]);
      if(histogram.isCalculated())
      {
        PLOT_GENERIC(id + ":normalizedHistogram", i, histogram.normalizedData[i]);
        PLOT_GENERIC(id + ":cumulativeHistogram", i, histogram.cumulativeData[i]);
      }
    }
  };

  //generate plot only for raw histogram
  void plotRaw(std::string id, Statistics::HistogramX& histogram) const
  {
    if(histogram.isCalculated())
    {
      for(int i = 0; i < histogram.size; i++)
      {
        PLOT_GENERIC(id + ":rawHistogram", i, histogram.rawData[i]);
      }
    }
  };

  //generate plot only for normalized histogram
  void plotNormalized(std::string id, Statistics::HistogramX& histogram) const
  {
    if(histogram.isCalculated())
    {
      for(int i = 0; i < histogram.size; i++)
      {
        PLOT_GENERIC(id + ":normalizedHistogram", i, histogram.normalizedData[i]);
      }
    }
  };

  //generate plot only for cumulated histogram
  void plotCumulated(std::string id, Statistics::HistogramX& histogram) const
  {
    if(histogram.isCalculated())
    {
      for(int i = 0; i < histogram.size; i++)
      {
        PLOT_GENERIC(id + ":cumulativeHistogram", i, histogram.cumulativeData[i]);
      }
    }
  };

};

#endif // _HistogramProvider_h_