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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#ifndef CAMMATERRORFUNCTIONV3_H
#define CAMMATERRORFUNCTIONV3_H

#include <Representations/Infrastructure/CameraInfo.h>
#include "Representations/Infrastructure/FieldInfo.h"
#include "Tools/CameraGeometry.h"
#include "Representations/Perception/LineGraphPercept.h"


#include "Eigen/Eigen"

// debug
#include "Tools/Debug/DebugRequest.h"
#include "Tools/Debug/DebugDrawings.h"
#include "Tools/Debug/DebugModify.h"
#include "Representations/Infrastructure/FrameInfo.h"

#include "Tools/Math/Optimizer.h"

class CamMatErrorFunctionV3
{
public:
    struct CalibrationDataSample {
        CalibrationDataSample(){}<--- Member variable 'CalibrationDataSample::headYaw' is not initialized in the constructor.<--- Member variable 'CalibrationDataSample::headPitch' is not initialized in the constructor.

        CalibrationDataSample(const Pose3D& chestPose, const LineGraphPercept& lineGraphPercept, const Vector2d& orientation, double headYaw  , double headPitch)
                             :chestPose(chestPose)   , orientation(orientation)      , headYaw(headYaw), headPitch(headPitch)
        {
            edgelsInImage.reserve(lineGraphPercept.edgelsInImage.size());
            for(std::vector<EdgelD>::const_iterator iter = lineGraphPercept.edgelsInImage.begin(); iter != lineGraphPercept.edgelsInImage.end(); ++iter){
                edgelsInImage.push_back(iter->point);
            }

            edgelsInImageTop.reserve(lineGraphPercept.edgelsInImageTop.size());
            for(std::vector<EdgelD>::const_iterator iter = lineGraphPercept.edgelsInImageTop.begin(); iter != lineGraphPercept.edgelsInImageTop.end(); ++iter){
                edgelsInImageTop.push_back(iter->point);
            }
        }

        //KinematicChain   kinematicChain;
        Pose3D chestPose; //work around, can't copy kinematic chain
        std::vector<Vector2d> edgelsInImage;
        std::vector<Vector2d> edgelsInImageTop;
        Vector2d orientation;
        double headYaw;
        double headPitch;
    };

    typedef std::vector<CalibrationDataSample> CalibrationData;
    typedef Eigen::Matrix<double, 11, 1> Parameter; // TODO: can this be the same typedef like in CameraMatrixCorrectorV3

    Optimizer::BoundedVariable<Parameter> const * bounds;
    Vector2d const * global_position;
    double const * global_orientation;

private:
    CalibrationData calibrationData;
    unsigned int numberOfResudials;

    DebugRequest&        theDebugRequest;
    DebugDrawings&       theDebugDrawings;
    //DebugModify&         theDebugModify;
    const FieldInfo&     theFieldInfo;
    const naoth::CameraInfo&    theCameraInfo;
    const naoth::CameraInfoTop& theCameraInfoTop;

    DebugRequest& getDebugRequest() {
        return theDebugRequest;
    }

    DebugDrawings& getDebugDrawings() {
        return theDebugDrawings;
    }

    const naoth::CameraInfo& getCameraInfo(int cameraID) const {
      if(cameraID == naoth::CameraInfo::Top) {
        return theCameraInfoTop;
      } else {
        return theCameraInfo;
      }
    }

    const std::vector<Vector2d>& getEdgelsInImage(std::vector<CalibrationDataSample>::const_iterator& sample, int cameraID) const {
      if(cameraID == naoth::CameraInfo::Top) {
        return sample->edgelsInImageTop;
      } else {
        return sample->edgelsInImage;
      }
    }

    void actual_plotting(const Parameter& parameter, naoth::CameraInfo::CameraID cameraID);

public:
    CamMatErrorFunctionV3(<--- Member variable 'CamMatErrorFunctionV3::global_position' is not initialized in the constructor.<--- Member variable 'CamMatErrorFunctionV3::global_orientation' is not initialized in the constructor.
        DebugRequest&        theDebugRequest,
        DebugDrawings&       theDebugDrawings,
        DebugModify&         /*theDebugModify*/,
        const FieldInfo&     theFieldInfo,
        const naoth::CameraInfo&    theCameraInfo,
        const naoth::CameraInfoTop& theCameraInfoTop
    ):
        bounds(nullptr),
        numberOfResudials(0),
        theDebugRequest(theDebugRequest),
        theDebugDrawings(theDebugDrawings),
        //theDebugModify(theDebugModify),
        theFieldInfo(theFieldInfo),
        theCameraInfo(theCameraInfo),
        theCameraInfoTop(theCameraInfoTop)
    {
        DEBUG_REQUEST_REGISTER("CamMatErrorFunctionV3:debug_drawings:only_bottom", "", false);
        DEBUG_REQUEST_REGISTER("CamMatErrorFunctionV3:debug_drawings:only_top", "", false);
        DEBUG_REQUEST_REGISTER("CamMatErrorFunctionV3:debug_drawings:draw_projected_edgels", "", true);
        DEBUG_REQUEST_REGISTER("CamMatErrorFunctionV3:debug_drawings:draw_matching_global",  "", false);
    }

    Eigen::VectorXd operator()(const Parameter& parameter) const;

    unsigned int getNumberOfResudials() const {
        return numberOfResudials;
    }

    void add(const CalibrationDataSample& c_data_sample)
    {
        unsigned int numNewResudials =
          (c_data_sample.edgelsInImage.empty()   ? 0 : 1) +
          (c_data_sample.edgelsInImageTop.empty()? 0 : 1);

        if (numNewResudials > 0) {
            calibrationData.push_back(c_data_sample);
            numberOfResudials += numNewResudials;
        }
    }

    void clear(){
        calibrationData.clear();
        numberOfResudials = 0;
    }

    void plot_CalibrationData(const Parameter& parameter){
        bool only_bottom = false;
        DEBUG_REQUEST("CamMatErrorFunctionV3:debug_drawings:only_bottom",
                      only_bottom = true;
        );

        bool only_top = false;
        DEBUG_REQUEST("CamMatErrorFunctionV3:debug_drawings:only_top",
                      only_top = true;
        );

        if(only_bottom && only_top){
            actual_plotting(parameter, naoth::CameraInfo::Bottom);
            actual_plotting(parameter, naoth::CameraInfo::Top);
        } else if (only_bottom) {
            actual_plotting(parameter, naoth::CameraInfo::Bottom);
        } else if (only_top) {
            actual_plotting(parameter, naoth::CameraInfo::Top);
        } else {
            actual_plotting(parameter, naoth::CameraInfo::Bottom);
            actual_plotting(parameter, naoth::CameraInfo::Top);
        }
    }

    void write_calibration_data_to_file();
    void read_calibration_data_from_file();
};

#endif // CAMMATERRORFUNCTIONV3_H