31 MultiMarkerBundle::MultiMarkerBundle(std::vector<int>& indices)
54 void Est(CvMat* state, CvMat* estimation,
void *param)
68 CvMat mat_translation_vector = cvMat(3, 1, CV_64F, tra);
69 CvMat mat_rotation_vector = cvMat(3, 1, CV_64F, rodr);
71 memcpy(tra, &(state->data.db[i*7]), 3*
sizeof(
double));
75 int n_points = n_markers*4;
76 for(
int j = 0; j < n_points; ++j)
78 int index = n_images*7 + 3*j;
80 double object_points[3] = {state->data.db[index+0],
81 state->data.db[index+1],
82 state->data.db[index+2]};
85 CvMat mat_object_points;
86 cvInitMatHeader(&mat_object_points, 1, 1, CV_64FC3, object_points);
89 CvMat mat_proj = cvMat(1, 1, CV_64FC2, proj);
91 cvProjectPoints2(&mat_object_points, &mat_rotation_vector,
92 &mat_translation_vector, &(camera->
calib_K),
95 index = i*n_points*2 + j*2;
96 estimation->data.db[index+0] = proj[0];
97 estimation->data.db[index+1] = proj[1];
112 cout<<
"Too few images! At least 1 images needed."<<endl;
121 int n_meas = 2*4*n_markers*frames;
122 CvMat* parameters_mat = cvCreateMat(n_params, 1, CV_64F);
123 CvMat* parameters_mask_mat = cvCreateMat(n_params, 1, CV_8U);
124 CvMat* measurements_mat = cvCreateMat(n_meas, 1, CV_64F);
125 CvMat* weight_mat = cvCreateMat(n_meas, 1, CV_64F);
126 cvZero(parameters_mat);
127 cvSet(parameters_mask_mat, cvScalar(1));
128 cvZero(measurements_mat);
129 cvSet(weight_mat, cvRealScalar(1.0));
134 for (
int j=0; j<4; j++) {
136 int index = frames*7 + i*(3*4) + j*3;
139 cvSet2D(parameters_mask_mat, index+0, 0, cvScalar(0));
140 cvSet2D(parameters_mask_mat, index+1, 0, cvScalar(0));
141 cvSet2D(parameters_mask_mat, index+2, 0, cvScalar(0));
149 cvSet2D(parameters_mask_mat, index+0, 0, cvScalar(0));
150 cvSet2D(parameters_mask_mat, index+1, 0, cvScalar(0));
151 cvSet2D(parameters_mask_mat, index+2, 0, cvScalar(0));
156 int n_measurements = 0;
157 for (
size_t f=0;
f < frames;
f++) {
160 CvMat tra = cvMat(3, 1, CV_64F, &(parameters_mat->data.db[
f*7+0]));
161 CvMat qua = cvMat(4, 1, CV_64F, &(parameters_mat->data.db[
f*7+3]));
168 for (
int j=0; j<4; j++) {
171 int index =
f*(n_markers*4*2) + i*(4*2) + j*2;
177 for (
int j=0; j<4; j++) {
179 int index =
f*(n_markers*4*2) + i*(4*2) + j*2;
180 cvmSet(weight_mat, index+0, 0, 0.);
181 cvmSet(weight_mat, index+1, 0, 0.);
194 optimization.
Optimize(parameters_mat, measurements_mat, stop, max_iter,
195 Est, 0, method, parameters_mask_mat, NULL, weight_mat);
236 for (
int j=0; j<4; j++) {
238 int index = frames*7 + i*(3*4) + j*3;
245 cvReleaseMat(¶meters_mat);
246 cvReleaseMat(¶meters_mask_mat);
247 cvReleaseMat(&measurements_mat);
259 const Marker* marker = *i;
260 int id = marker->
GetId();
262 if (index < 0)
continue;
264 for (
int j = 0; j<4; j++) {
int optimization_keyframes
void GetRodriques(CvMat *mat) const
Returns the rotation in rotation vector form.
std::vector< PointDouble > marker_corners_img
Marker corners in image coordinates.
virtual unsigned long GetId() const
Get id for this marker This is used e.g. in MarkerDetector to associate a marker id with an appropria...
int measurements_index(int frame, int marker_id, int marker_corner)
std::vector< int > marker_status
double Optimize(CvMat *parameters, CvMat *measurements, double stop, int max_iter, EstimateCallback Estimate, void *param=0, OptimizeMethod method=LEVENBERGMARQUARDT, CvMat *parameters_mask=0, CvMat *J_mat=0, CvMat *weights=0)
Runs the optimization loop with selected parameters.
bool Optimize(Camera *_cam, double stop, int max_iter, Optimization::OptimizeMethod method=Optimization::TUKEY_LM)
Runs the bundle adjustment optimization.
Base class for using MultiMarker.
TFSIMD_FORCE_INLINE const tfScalar & y() const
std::map< int, CvPoint3D64f > pointcloud
Non-linear optimization routines. There are three methods implemented that include Gauss-Newton...
int get_id_index(int id, bool add_if_missing=false)
std::vector< int > marker_indices
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
OptimizeMethod
Selection between the algorithm used in optimization. Following should be noticed: ...
int pointcloud_index(int marker_id, int marker_corner, bool add_if_missing=false)
Pose representation derived from the Rotation class
TFSIMD_FORCE_INLINE const tfScalar & x() const
Basic 2D Marker functionality.
std::map< int, PointDouble > measurements
TFSIMD_FORCE_INLINE const tfScalar & z() const
Iterator type for traversing templated Marker vector without the template.
void _MeasurementsAdd(MarkerIterator &begin, MarkerIterator &end, const Pose &camera_pose)
This file implements an algorithm to create a multi-marker field configuration.
void Est(CvMat *state, CvMat *estimation, void *param)
void MeasurementsReset()
Resets the measurements and camera poses that are stored for bundle adjustment. If something goes fro...
void SetQuaternion(CvMat *mat)
Sets the rotation from given quaternion.
virtual MarkerIterator & reset()=0
std::vector< Pose > camera_poses
double optimization_error