/
AlignMarkerMap.h
79 lines (67 loc) · 2.24 KB
/
AlignMarkerMap.h
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
#pragma once
#include "Constants_Plugin_ArUco.h"
#include "ofxRulr/Nodes/Base.h"
#include "ofxRulr/Utils/CaptureSet.h"
#include "ofxNonLinearFit.h"
#include "MarkerMap.h"
#include <aruco/aruco.h>
namespace ofxRulr {
namespace Nodes {
namespace ArUco {
class PLUGIN_ARUCO_EXPORTS AlignMarkerMap : public Nodes::Base {
public:
enum class Plane : int {
X, Y, Z
};
enum class Points : int {
All, Center
};
class Constraint : public Utils::AbstractCaptureSet::BaseCapture {
public:
Constraint();
string getDisplayString() const override;
ofParameter<int> markerID{ "Marker ID", 0 };
ofParameter<int> plane{ "Plane", (int)Plane::X };
ofParameter<float> offset{ "Offset", 0.0f };
ofParameter<int> points{ "Points", (int)Points::All };
ofParameter<float> residual{ "Residual (m)", 0.0f };
float getResidual(const ofMatrix4x4 & transform);
void updatePoints(shared_ptr<aruco::MarkerMap>);
void drawWorld();
protected:
ofxCvGui::ElementPtr getDataDisplay() override;
void serialize(Json::Value &);
void deserialize(const Json::Value &);
vector<ofVec3f> cachedPoints;
};
class Model : public ofxNonLinearFit::Models::Base<shared_ptr<Constraint>, Model> {
public:
unsigned int getParameterCount() const override;
void getResidual(shared_ptr<Constraint>, double & residual, double * gradient) const override;
void evaluate(shared_ptr<Constraint> &) const override;
void cacheModel() override;
ofMatrix4x4 getTransform() const;
protected:
ofMatrix4x4 cachedModel;
};
AlignMarkerMap();
string getTypeName() const override;
void init();
void update();
void drawWorldStage();
ofxCvGui::PanelPtr getPanel() override;
void populateInspector(ofxCvGui::InspectArguments &);
void serialize(Json::Value &);
void deserialize(const Json::Value &);
void fit();
protected:
Utils::CaptureSet<Constraint> constraints;
ofxCvGui::PanelPtr panel;
struct : ofParameterGroup {
ofParameter<float> residual{ "Residual", 0.0f };
PARAM_DECLARE("AlignMarkerMap", residual);
} parameters;
};
}
}
}