35 int count = projection->rows;
36 CvMat rot_mat = cvMat(3, 1, CV_64F, &(state->data.db[0+0]));
37 double zeros[3] = {0};
38 CvMat zero_tra = cvMat(3, 1, CV_64F, zeros);
39 cvReshape(projection, projection, 2, 1);
41 cvReshape(projection, projection, 1, count);
44 void TrackerOrientation::Reset()
47 _pose.Mirror(
false,
true,
true);
51 double TrackerOrientation::Track(IplImage *
image)
53 UpdateRotationOnly(image, 0);
57 bool TrackerOrientation::UpdatePose(IplImage *
image)
59 int count_points = _F_v.size();
60 if(count_points < 6)
return false;
62 CvMat* _M = cvCreateMat(count_points, 1, CV_64FC3);
63 CvMat* image_observations = cvCreateMat(count_points*2, 1, CV_64F);
67 for(map<int,Feature>::iterator it=_F_v.begin(); it!=_F_v.end(); it++)
69 if((it->second.status3D == Feature::USE_FOR_POSE ||
70 it->second.status3D == Feature::IS_INITIAL) &&
71 it->second.status2D == Feature::IS_TRACKED)
73 _M->data.db[ind*3+0] = it->second.point3d.x;
74 _M->data.db[ind*3+1] = it->second.point3d.y;
75 _M->data.db[ind*3+2] = it->second.point3d.z;
77 image_observations->data.db[ind*2+0] = it->second.point.x;
78 image_observations->data.db[ind*2+1] = it->second.point.y;
85 cvReleaseMat(&image_observations);
90 double rot[3]; CvMat rotm = cvMat(3, 1, CV_64F, rot);
91 _pose.GetRodriques(&rotm);
93 CvMat* par = cvCreateMat(3, 1, CV_64F);
94 memcpy(&(par->data.db[0+0]), rot, 3*
sizeof(
double));
97 CvRect
r; r.x = 0; r.y = 0; r.height = ind; r.width = 1;
99 cvGetSubRect(_M, &Msub, r);
100 _object_model = &Msub;
103 CvMat image_observations_sub;
104 cvGetSubRect(image_observations, &image_observations_sub, r);
109 memcpy(rot, &(par->data.db[0+0]), 3*
sizeof(
double));
110 _pose.SetRodriques(&rotm);
115 cvReleaseMat(&image_observations);
121 bool TrackerOrientation::UpdateRotationOnly(IplImage *
gray, IplImage *
image)
123 if(gray->nChannels != 1)
return false;
124 if(!_grsc) _grsc = cvCreateImage(cvSize(_xres, _yres), 8, 1);
125 if((_xres!=_grsc->width)||(_yres!=_grsc->height))
126 cvResize(gray, _grsc);
128 _grsc->imageData = gray->imageData;
130 map<int,Feature>::iterator it ;
131 for(it = _F_v.begin(); it != _F_v.end(); it++)
132 it->second.status2D = Feature::NOT_TRACKED;
138 for (
int i = 0; i < _ft.feature_count; i++)
141 _F_v[id].point = _ft.features[i];
142 _F_v[id].point.x *= _image_scale;
143 _F_v[id].point.y *= _image_scale;
144 _F_v[id].status2D = Feature::IS_TRACKED;
147 if(_F_v[
id].status3D == Feature::IS_OUTLIER)
156 while(it != _F_v.end())
158 if(it->second.status2D == Feature::NOT_TRACKED)
167 while(it != _F_v.end())
176 CvPoint2D32f fpu = f->
point;
177 _camera->Undistort(fpu);
180 int object_scale = 1;
183 wx = object_scale*(fpu.x-_camera->calib_K_data[0][2])/_camera->calib_K_data[0][0];
184 wy = object_scale*(fpu.y-_camera->calib_K_data[1][2])/_camera->calib_K_data[1][1];
191 double Xd[4] = {wx, wy, wz, 1};
192 CvMat Xdm = cvMat(4, 1, CV_64F, Xd);
194 CvMat Pdm = cvMat(4, 4, CV_64F, Pd);
196 cvMatMul(&Pdm, &Xdm, &Xdm);
202 f->
status3D = Feature::USE_FOR_POSE;
208 cvCircle(image, cvPoint(
int(f->
point.x),
int(f->
point.y)), 3, CV_RGB(255,0,0), 1);
209 else if(f->
status3D == Feature::USE_FOR_POSE)
210 cvCircle(image, cvPoint(
int(f->
point.x),
int(f->
point.y)), 3, CV_RGB(0,255,0), 1);
211 else if(f->
status3D == Feature::IS_INITIAL)
212 cvCircle(image, cvPoint(
int(f->
point.x),
int(f->
point.y)), 3, CV_RGB(0,0,255), 1);
213 else if(f->
status3D == Feature::IS_OUTLIER)
214 cvCircle(image, cvPoint(
int(f->
point.x),
int(f->
point.y)), 2, CV_RGB(255,0,255), 1);
220 if( f->
status3D == Feature::USE_FOR_POSE ||
221 f->
status3D == Feature::IS_INITIAL )
224 CvMat p3dm = cvMat(1, 1, CV_64FC3, p3d);
226 CvMat p2dm = cvMat(2, 1, CV_64F, p2d);
227 cvReshape(&p2dm, &p2dm, 2, 1);
230 _pose.GetMatrixGL(gl_mat);
231 _camera->ProjectPoints(&p3dm, gl_mat, &p2dm);
234 cvLine(image, cvPoint(
int(p2d[0]),
int(p2d[1])), cvPoint(
int(f->
point.x),
int(f->
point.y)), CV_RGB(255,0,255));
237 if(dist > _outlier_limit)
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.
Track orientation based only on features in the image plane.
Non-linear optimization routines. There are three methods implemented that include Gauss-Newton...
static void Project(CvMat *state, CvMat *projection, void *x)
This file implements several optimization algorithms.
Pose representation derived from the Rotation class
enum alvar::TrackerOrientation::Feature::@2 status3D
void GetMatrix(CvMat *mat) const
This file implements an orientation tracker.