/* per-point error estimate (autodifferentiated)ctor takes addrs of two constant rays() takes global rotation and translation paramsand the fitted point for this ray pairresidual gets angles between fitted and given rays*/struct rayCloudError {rayCloudError( const double * pl, const double * pr ): l_(pl), r_(pr) {}// angle between 2 unit vectors, and its sine and cosinetemplate <typename T>T uva( const T * r1,const T * r2,T * sa, T * ca )const {*ca = ceres::DotProduct(r1, r2);T t[3] = {r2[0] - r1[0] * *ca,r2[1] - r1[1] * *ca,r2[2] - r1[2] * *ca};*sa = sqrt(ceres::DotProduct(t, t));return atan2(*sa, *ca);}// normalize a vector, return its lengthtemplate <typename T>T nrv( T* v ) const {T l = sqrt(ceres::DotProduct(v, v));T s = T(0.0);if( l > T(1.e-8)) s = T(1.0) / l;v[0] *= s;v[1] *= s;v[2] *= s;return l;}template <typename T>bool operator()( const T * const rrrxyz, // [6] globalconst T * ppt, // [3] per pointT * residuals ) const // [2] per point{T ds, dc, p1[3], p2[3];ceres::AngleAxisRotatePoint( rrrxyz, ppt, p2 );for(int i = 0; i < 3; i++){p1[i] = ppt[i];p2[i] = p2[i] - rrrxyz[3 + i];}T l1 = nrv( p1 );T l2 = nrv( p2 );residuals[0] = uva( p1, (const T*)l_, &ds, &dc );residuals[1] = uva( p2, (const T*)r_, &ds, &dc );return true;}static ceres::CostFunction* Create( const double * lft,const double * rgt ) {return (new ceres::AutoDiffCostFunction<rayCloudError, 2, 6, 3>(new rayCloudError(lft, rgt)));}// pointers to raysconst double * l_, * r_;};
--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/1b5019f4-6216-41dc-86e6-2a24d990ffb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/7140be66-a039-49f1-a206-d3ba769594ad%40googlegroups.com.
...
Error in evaluating the ResidualBlock.There are two possible reasons. Either the CostFunction did not evaluate and fill allresidual and jacobians that were requested or there was a non-finite value (nan/infinite)generated during the or jacobian computation.Residual Block size: 2 parameter blocks x 2 residualsFor each parameter block, the value of the parameters are printed in the first columnand the value of the jacobian under the corresponding residual. If a ParameterBlock washeld constant then the corresponding jacobian is printed as 'Not Computed'. If an entryof the Jacobian/residual array was requested but was not written to by user code, it isindicated by 'Uninitialized'. This is an error. Residuals or Jacobian values evaluatingto Inf or NaN is also an error.Residuals: 1.5708 1.5708Parameter Block 0, size: 60 | nan nan-0 | nan nan0 | nan nan1 | nan nan0 | nan nan0 | nan nanParameter Block 1, size: 30 | nan nan0 | nan nan0 | nan nanD:\solver\ceres-solver-1.8.0\internal\ceres\trust_region_minimizer.cc:133 Terminating: Residual and Jacobian evaluation failed.
/* rayBundler.cpp copyright T K Sharplesspart of the Panini stitching librariesFit a 3d model to paired rays on two calibratedcameras (whose intrinsics have already been usedto compute the ray directions).The model isCamera A defines the coordinate system upto scale.Scale unit is the distance between cameras.Camera B is rotated by RR and translatedby 1 unit in the direction epi.Each ray pair has a fitted 3D point.If the rays are correctly matched points from twoviews of the same scene, the differences of polarangles with respect to epi (that are not 0) shouldall have the same sign.The main function, alignRayClouds, initializes the3D points using the passed values of the rotationand translation parameters. It tries to validatethe matches and may rearrange the data arrays, puttingrejected pairs at the end. It returns the number ofaccepted pairs, that belong to the final model.The optimizer is basically the ceres simple bundleradjuster example with camera intrinsics removed fromthe error evaluation. The new error measure is theangle between the fitted and given rays.*/#include "rayBundler.h"#include "ceres/ceres.h"#include "ceres/rotation.h"#include "spheregeom.h"
// bundle adjustmentstatic bool adjust( const double * pa,const double * pb,double * ppt,int npnts,double * rrrxyz){ceres::Problem problem;for( int i = 0; i < npnts; i++ ){ceres::CostFunction * pcf =rayCloudError::Create( pa+3*i, pb+3*i );problem.AddResidualBlock( pcf,NULL,rrrxyz,ppt+3*i );}ceres::Solver::Options options;options.logging_type = ceres::SILENT;options.linear_solver_type = ceres::DENSE_SCHUR;ceres::Solver::Summary summary;ceres::Solve(options, &problem, &summary );std::cout<< summary.FullReport() << "\n";// return false if optimizer failedreturn summary.error.size() == 0;}int alignRayClouds( const double * raysA, // input unit vectorsconst double * raysB, // as A-B pairsdouble * pnts, // output 3D pointsint npnts,double & yaw, double & pitch, double & roll, // output rotation of Bdouble & epix, double & epiy, double & epiz // output translation of B){double pry[3] = { pitch, roll, yaw };double RM[9];ceres::EulerAnglesToRotationMatrix<double>( pry, 3, RM );double rrrxyz[6] = { 0, 0, 0, epix, epiy, epiz };// initialize the angle-axis rotationceres::RotationMatrixToAngleAxis( RM, rrrxyz );#if 0 // makes no difference// try perturbing...for(int i = 0; i < 6; i++ )rrrxyz[i] += 0.0005;#endif/* initialize the 3D pointsapply the given rotation and translation to raysBthen compute point of nearest approach of rays*/for( int i = 0; i < npnts; i++ ){int k = 3 * i;const double * ra = raysA + k,* rb = raysB + k;double * pt = pnts + k;double p2[3];ceres::AngleAxisRotatePoint( rrrxyz, rb, p2 );gp3d orga(0,0,0),orgb(epix,epiy,epiz),pnta(ra),pntb(p2);plck3d pla(orga, pnta),plb(orgb, pntb);seg3d seg;double d = pla.nearPnts(plb, 0, &seg);gp3d m = seg.midpoint();if(m.isNaN()){m = gp3d(-1, -1, -1);} else if(m.isZero()){m = gp3d(1, 1, -1);}// makes no difference m.clear();// makes no difference m = gp3d(0,0,-1000);m.put(pt);}int nacc = npnts;bool ok = true;ok = adjust(raysA, raysB, pnts, nacc, rrrxyz);if(ok) return nacc;return 0;}
...
...
--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/4223dd0f-5082-4eb3-b157-3d57324133f1%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/86f6d65d-51c1-4f64-b8a2-2bc911b19a66%40googlegroups.com.
...
--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/80bce433-befe-4978-bc01-27fe3c86da4e%40googlegroups.com.
...
--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/48eaa08f-1a03-42f2-a981-7a339a0914b8%40googlegroups.com.