📄 eucsbademo.c
字号:
*/static void img_projsS_jac_x(double *p, struct sba_crsm *idxij, int *rcidxs, int *rcsubs, double *jac, void *adata){ register int i, j; int cnp, pnp, mnp; double *pqr, *pt, *ppt, *pB, *Kparms, *camparams; //int n; int m, nnz, Bsz, idx; struct globs_ *gl; gl=(struct globs_ *)adata; cnp=gl->cnp; pnp=gl->pnp; mnp=gl->mnp; Kparms=gl->intrcalib; camparams=gl->camparams; //n=idxij->nr; m=idxij->nc; Bsz=mnp*pnp; for(j=0; j<m; ++j){ /* j-th camera parameters */ pqr=camparams+j*cnp; pt=pqr+3; // quaternion vector part has 3 elements nnz=sba_crsm_col_elmidxs(idxij, j, rcidxs, rcsubs); /* find nonzero hx_ij, i=0...n-1 */ for(i=0; i<nnz; ++i){ ppt=p + rcsubs[i]*pnp; idx=idxij->val[rcidxs[i]]; pB=jac + idx*Bsz; // set pB to point to B_ij calcImgProjJacS(Kparms, pqr, pt, ppt, (double (*)[3])pB); // evaluate dQ/da in pB } }}/****************************************************************************************************//* MEASUREMENT VECTOR AND JACOBIAN COMPUTATION FOR VARYING CAMERA INTRINSICS, POSE AND 3D STRUCTURE *//****************************************************************************************************//*** MEASUREMENT VECTOR AND JACOBIAN COMPUTATION FOR THE SIMPLE DRIVERS ***//* A note about the computation of Jacobians below: * * When performing BA that includes the camera intrinsics, it would be * very desirable to allow for certain parameters such as skew, aspect * ratio and principal point to be fixed. The straighforward way to * implement this would be to code a separate version of the Jacobian * computation routines for each subset of non-fixed parameters. Here, * this is bypassed by developing only one set of Jacobian computation * routines which estimate the former for all 5 intrinsics and then set * the columns corresponding to fixed parameters to zero. *//* FULL BUNDLE ADJUSTMENT, I.E. SIMULTANEOUS ESTIMATION OF CAMERA AND STRUCTURE PARAMETERS *//* Given the parameter vectors aj and bi of camera j and point i, computes in xij the * predicted projection of point i on image j */static void img_projKRTS(int j, int i, double *aj, double *bi, double *xij, void *adata){ calcImgProj(aj, aj+5, aj+5+3, bi, xij); // 5 for the calibration + 3 for the quaternion's vector part}/* Given the parameter vectors aj and bi of camera j and point i, computes in Aij, Bij the * jacobian of the predicted projection of point i on image j */static void img_projKRTS_jac(int j, int i, double *aj, double *bi, double *Aij, double *Bij, void *adata){struct globs_ *gl;int ncK; calcImgProjJacKRTS(aj, aj+5, aj+5+3, bi, (double (*)[5+6])Aij, (double (*)[3])Bij); // 5 for the calibration + 3 for the quaternion's vector part /* clear the columns of the Jacobian corresponding to fixed calibration parameters */ gl=(struct globs_ *)adata; ncK=gl->nccalib; if(ncK){ int cnp, mnp, j0; cnp=gl->cnp; mnp=gl->mnp; j0=5-ncK; for(i=0; i<mnp; ++i, Aij+=cnp) for(j=j0; j<5; ++j) Aij[j]=0.0; // Aij[i*cnp+j]=0.0; }}/* BUNDLE ADJUSTMENT FOR CAMERA PARAMETERS ONLY *//* Given the parameter vector aj of camera j, computes in xij the * predicted projection of point i on image j */static void img_projKRT(int j, int i, double *aj, double *xij, void *adata){ int pnp; double *ptparams; struct globs_ *gl; gl=(struct globs_ *)adata; pnp=gl->pnp; ptparams=gl->ptparams; calcImgProj(aj, aj+5, aj+5+3, ptparams+i*pnp, xij); // 5 for the calibration + 3 for the quaternion's vector part}/* Given the parameter vector aj of camera j, computes in Aij * the jacobian of the predicted projection of point i on image j */static void img_projKRT_jac(int j, int i, double *aj, double *Aij, void *adata){struct globs_ *gl;double *ptparams;int pnp, ncK; gl=(struct globs_ *)adata; pnp=gl->pnp; ptparams=gl->ptparams; calcImgProjJacKRT(aj, aj+5, aj+5+3, ptparams+i*pnp, (double (*)[5+6])Aij); // 5 for the calibration + 3 for the quaternion's vector part /* clear the columns of the Jacobian corresponding to fixed calibration parameters */ ncK=gl->nccalib; if(ncK){ int cnp, mnp, j0; cnp=gl->cnp; mnp=gl->mnp; j0=5-ncK; for(i=0; i<mnp; ++i, Aij+=cnp) for(j=j0; j<5; ++j) Aij[j]=0.0; // Aij[i*cnp+j]=0.0; }}/* BUNDLE ADJUSTMENT FOR STRUCTURE PARAMETERS ONLY *//* Given the parameter vector bi of point i, computes in xij the * predicted projection of point i on image j */static void img_projKS(int j, int i, double *bi, double *xij, void *adata){ int cnp; double *camparams, *aj; struct globs_ *gl; gl=(struct globs_ *)adata; cnp=gl->cnp; camparams=gl->camparams; aj=camparams+j*cnp; calcImgProj(aj, aj+5, aj+5+3, bi, xij); // 5 for the calibration + 3 for the quaternion's vector part}/* Given the parameter vector bi of point i, computes in Bij * the jacobian of the predicted projection of point i on image j */static void img_projKS_jac(int j, int i, double *bi, double *Bij, void *adata){ int cnp; double *camparams, *aj; struct globs_ *gl; gl=(struct globs_ *)adata; cnp=gl->cnp; camparams=gl->camparams; aj=camparams+j*cnp; calcImgProjJacS(aj, aj+5, aj+5+3, bi, (double (*)[3])Bij); // 5 for the calibration + 3 for the quaternion's vector part}/*** MEASUREMENT VECTOR AND JACOBIAN COMPUTATION FOR THE EXPERT DRIVERS ***//* FULL BUNDLE ADJUSTMENT, I.E. SIMULTANEOUS ESTIMATION OF CAMERA AND STRUCTURE PARAMETERS *//* Given a parameter vector p made up of the 3D coordinates of n points and the parameters of m cameras, compute in * hx the prediction of the measurements, i.e. the projections of 3D points in the m images. The measurements * are returned in the order (hx_11^T, .. hx_1m^T, ..., hx_n1^T, .. hx_nm^T)^T, where hx_ij is the predicted * projection of the i-th point on the j-th camera. * Notice that depending on idxij, some of the hx_ij might be missing * */static void img_projsKRTS_x(double *p, struct sba_crsm *idxij, int *rcidxs, int *rcsubs, double *hx, void *adata){ register int i, j; int cnp, pnp, mnp; double *pa, *pb, *pqr, *pt, *ppt, *pmeas, *pcalib; //int n; int m, nnz; struct globs_ *gl; gl=(struct globs_ *)adata; cnp=gl->cnp; pnp=gl->pnp; mnp=gl->mnp; //n=idxij->nr; m=idxij->nc; pa=p; pb=p+m*cnp; for(j=0; j<m; ++j){ /* j-th camera parameters */ pcalib=pa+j*cnp; pqr=pcalib+5; pt=pqr+3; // quaternion vector part has 3 elements nnz=sba_crsm_col_elmidxs(idxij, j, rcidxs, rcsubs); /* find nonzero hx_ij, i=0...n-1 */ for(i=0; i<nnz; ++i){ ppt=pb + rcsubs[i]*pnp; pmeas=hx + idxij->val[rcidxs[i]]*mnp; // set pmeas to point to hx_ij calcImgProj(pcalib, pqr, pt, ppt, pmeas); // evaluate Q in pmeas } }}/* Given a parameter vector p made up of the 3D coordinates of n points and the parameters of m cameras, compute in * jac the jacobian of the predicted measurements, i.e. the jacobian of the projections of 3D points in the m images. * The jacobian is returned in the order (A_11, ..., A_1m, ..., A_n1, ..., A_nm, B_11, ..., B_1m, ..., B_n1, ..., B_nm), * where A_ij=dx_ij/db_j and B_ij=dx_ij/db_i (see HZ). * Notice that depending on idxij, some of the A_ij, B_ij might be missing * */static void img_projsKRTS_jac_x(double *p, struct sba_crsm *idxij, int *rcidxs, int *rcsubs, double *jac, void *adata){ register int i, j, ii, jj; int cnp, pnp, mnp, ncK; double *pa, *pb, *pqr, *pt, *ppt, *pA, *pB, *pcalib; //int n; int m, nnz, Asz, Bsz, ABsz, idx; struct globs_ *gl; gl=(struct globs_ *)adata; cnp=gl->cnp; pnp=gl->pnp; mnp=gl->mnp; ncK=gl->nccalib; //n=idxij->nr; m=idxij->nc; pa=p; pb=p+m*cnp; Asz=mnp*cnp; Bsz=mnp*pnp; ABsz=Asz+Bsz; for(j=0; j<m; ++j){ /* j-th camera parameters */ pcalib=pa+j*cnp; pqr=pcalib+5; pt=pqr+3; // quaternion vector part has 3 elements nnz=sba_crsm_col_elmidxs(idxij, j, rcidxs, rcsubs); /* find nonzero hx_ij, i=0...n-1 */ for(i=0; i<nnz; ++i){ ppt=pb + rcsubs[i]*pnp; idx=idxij->val[rcidxs[i]]; pA=jac + idx*ABsz; // set pA to point to A_ij pB=pA + Asz; // set pB to point to B_ij calcImgProjJacKRTS(pcalib, pqr, pt, ppt, (double (*)[5+6])pA, (double (*)[3])pB); // evaluate dQ/da, dQ/db in pA, pB /* clear the columns of the Jacobian corresponding to fixed calibration parameters */ if(ncK){ int jj0=5-ncK; for(ii=0; ii<mnp; ++ii, pA+=cnp) for(jj=jj0; jj<5; ++jj) pA[jj]=0.0; // pA[ii*cnp+jj]=0.0; } } }}/* BUNDLE ADJUSTMENT FOR CAMERA PARAMETERS ONLY *//* Given a parameter vector p made up of the parameters of m cameras, compute in * hx the prediction of the measurements, i.e. the projections of 3D points in the m images. * The measurements are returned in the order (hx_11^T, .. hx_1m^T, ..., hx_n1^T, .. hx_nm^T)^T, * where hx_ij is the predicted projection of the i-th point on the j-th camera. * Notice that depending on idxij, some of the hx_ij might be missing * */static void img_projsKRT_x(double *p, struct sba_crsm *idxij, int *rcidxs, int *rcsubs, double *hx, void *adata){ register int i, j; int cnp, pnp, mnp; double *pqr, *pt, *ppt, *pmeas, *pcalib, *ptparams; //int n; int m, nnz; struct globs_ *gl; gl=(struct globs_ *)adata; cnp=gl->cnp; pnp=gl->pnp; mnp=gl->mnp; ptparams=gl->ptparams; //n=idxij->nr; m=idxij->nc; for(j=0; j<m; ++j){ /* j-th camera parameters */ pcalib=p+j*cnp; pqr=pcalib+5; pt=pqr+3; // quaternion vector part has 3 elements nnz=sba_crsm_col_elmidxs(idxij, j, rcidxs, rcsubs); /* find nonzero hx_ij, i=0...n-1 */ for(i=0; i<nnz; ++i){ ppt=ptparams + rcsubs[i]*pnp; pmeas=hx + idxij->val[rcidxs[i]]*mnp; // set pmeas to point to hx_ij calcImgProj(pcalib, pqr, pt, ppt, pmeas); // evaluate Q in pmeas } }}/* Given a parameter vector p made up of the parameters of m cameras, compute in jac * the jacobian of the predicted measurements, i.e. the jacobian of the projections of 3D points in the m images. * The jacobian is returned in the order (A_11, ..., A_1m, ..., A_n1, ..., A_nm), * where A_ij=dx_ij/db_j (see HZ). * Notice that depending on idxij, some of the A_ij might be missing * */static void img_projsKRT_jac_x(double *p, struct sba_crsm *idxij, int *rcidxs, int *rcsubs, double *jac, void *adata){ register int i, j, ii, jj; int cnp, pnp, mnp, ncK; double *pqr, *pt, *ppt, *pA, *pcalib, *ptparams; //int n; int m, nnz, Asz, idx; struct globs_ *gl; gl=(struct globs_ *)adata; cnp=gl->cnp; pnp=gl->pnp; mnp=gl->mnp; ncK=gl->nccalib; ptparams=gl->ptparams; //n=idxij->nr; m=idxij->nc; Asz=mnp*cnp; for(j=0; j<m; ++j){ /* j-th camera parameters */ pcalib=p+j*cnp; pqr=pcalib+5; pt=pqr+3; // quaternion vector part has 3 elements nnz=sba_crsm_col_elmidxs(idxij, j, rcidxs, rcsubs); /* find nonzero hx_ij, i=0...n-1 */ for(i=0; i<nnz; ++i){ ppt=ptparams + rcsubs[i]*pnp; idx=idxij->val[rcidxs[i]]; pA=jac + idx*Asz; // set pA to point to A_ij calcImgProjJacKRT(pcalib, pqr, pt, ppt, (double (*)[5+6])pA); // evaluate dQ/da in pA /* clear the columns of the Jacobian corresponding to fixed calibration parameters */ if(ncK){ int jj0; jj0=5-ncK; for(ii=0; ii<mnp; ++ii, pA+=cnp) for(jj=jj0; jj<5; ++jj) pA[jj]=0.0; // pA[ii*cnp+jj]=0.0; } } }}/* BUNDLE ADJUSTMENT FOR STRUCTURE PARAMETERS ONLY *//* Given a parameter vector p made up of the 3D coordinates of n points and the parameters of m cameras, compute in * hx the prediction of the measurements, i.e. the projections of 3D points in the m images. The measurements * are returned in the order (hx_11^T, .. hx_1m^T, ..., hx_n1^T, .. hx_nm^T)^T, where hx_ij is the predicted * projection of the i-th point on the j-th camera. * Notice that depending on idxij, some of the hx_ij might be missing * */static void img_projsKS_x(double *p, struct sba_crsm *idxij, int *rcidxs, int *rcsubs, double *hx, void *adata){ register int i, j; int cnp, pnp, mnp; double *pqr, *pt, *ppt, *pmeas, *pcalib, *camparams; //int n;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -