Hi all,
I'm trying to implement a dynamic, incremental, BA problem with 3D points (specifically blob centers).
I use a function to add a new parameter block when needed:
bool BlobCloudOptimizer::AddBlobAndMeasurement( Point2d z,
Point3d p,
CoordinateTransformation3D T_C0_Ck,
MonoCalibration *Calib)
{
int nBlobs = problem.NumParameterBlocks();
bool graphics = true;
vector<double*> parameterBlocks;
problem.GetParameterBlocks(¶meterBlocks);
parameters[3*parameterBlocks.size() + 0] = p.x;
parameters[3*parameterBlocks.size() + 1] = p.y;
parameters[3*parameterBlocks.size() + 2] = p.z;
ceres::NumericDiffCostFunction<BlobImageResidual, ceres::CENTRAL, 2, 3>* cost_function =
new ceres::NumericDiffCostFunction<BlobImageResidual, ceres::CENTRAL, 2, 3>(new BlobImageResidual(z, T_C0_Ck, Calib));
numBlocks++;
ceres::LossFunction* loss_function = NULL;
if (HuberParam >= 0)
loss_function = new ceres::HuberLoss(HuberParam);
problem.AddParameterBlock(parameters + 3*parameterBlocks.size(), 3, NULL);
problem.AddResidualBlock(cost_function, loss_function, parameters + 3*parameterBlocks.size());
RES_TimesMeasured.push_back(1);
RES_TimesPredicted.push_back(1);
RES_LastIterationState.push_back(3);
RES_Life.push_back(1);
nBlobs = problem.NumParameterBlocks();
return true;
}
As expected nBlobs increases when I add a new Parameter block, unless I have deleted a parameter block before!!
bool BlobCloudOptimizer::DeleteBlob(int pointIndex,
vector<double*> *parameterBlocks)
{
if (parameterBlocks == 0)
problem.GetParameterBlocks(parameterBlocks);
int nBlobs = problem.NumParameterBlocks();
problem.RemoveParameterBlock(parameterBlocks->at(pointIndex));
nBlobs = problem.NumParameterBlocks();
RES_TimesPredicted.erase(RES_TimesPredicted.begin() + pointIndex);
RES_TimesMeasured.erase(RES_TimesMeasured.begin() + pointIndex);
RES_Life.erase(RES_Life.begin() + pointIndex);
RES_LastIterationState.erase(RES_LastIterationState.begin() + pointIndex);
return true;
}
In this case, nBlobs is always decremented as expected, but after the first execution of this function, BlobCloudOptimizer::AddBlobAndMeasurement stops working.
I'm using ceres 1.10.0 in Visual Studio 2010, my target is x64 . My residual function looks like this:
class BlobImageResidual
{
public:
BlobImageResidual(Point2d z, CoordinateTransformation3D T_C0_Ck, MonoCalibration *Calib)
: z(z), T_C0_Ck(T_C0_Ck), Calib(Calib)
{}
bool operator() (const double * const parameters, double* residuals) const
{
vector<Point3d> p_vec;
Point3d pW(parameters[0], parameters[1], parameters[2]);
p_vec.push_back(pW);
vector<Point2d> h_vec = Projection::project(T_C0_Ck, Calib, p_vec);
Point2d dif = z - h_vec[0];
residuals[0] = dif.x;
residuals[1] = dif.y;
return true;
}
Point2d z;
CoordinateTransformation3D T_C0_Ck;
MonoCalibration *Calib;
};
Any clue of what's going on?
Thanks in advance. Regards,
Jorge Romeo