[ceres-solver] AddResidualBlock after RemoveParameterBlock

92 views
Skip to first unread message

Luis-Jorge Romeo

unread,
Feb 18, 2015, 8:19:40 AM2/18/15
to ceres-...@googlegroups.com
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(&parameterBlocks);

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

Sameer Agarwal

unread,
Feb 19, 2015, 5:37:48 AM2/19/15
to ceres-...@googlegroups.com
Hi Jorge,
Sorry for the delay in replying.  What do you mean by BlobCloudOptimizer::AddBlobAndMeasurement stops working?
Sameer


--
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/CAB_M7uVCUGS5wR_6rM1Fn0rKqrgn-n%3DuVFej13NsNnpNpr91XA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Luis-Jorge Romeo

unread,
Feb 19, 2015, 6:27:54 AM2/19/15
to ceres-...@googlegroups.com
Hi Sameer, thanks for the reply.

Debugging my algorithm, I realised that I was trying to add a parameter block with a memory address already in use. Since my app is Windows native, I have stdout disabled so I coudn't see the corresponding ceres' error message. Should have done this before posting. My fault. 

Thanks for your time anyway.

Jorge

Sameer Agarwal

unread,
Feb 19, 2015, 6:42:18 AM2/19/15
to ceres-...@googlegroups.com
No worries, happy to help.

Reply all
Reply to author
Forward
0 new messages