Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I print a variable in the ComputeError() in the terminal? #759

Open
yangliu9527 opened this issue Jan 25, 2024 · 3 comments
Open

Comments

@yangliu9527
Copy link

I want to print some values calculated in the computeError() function of an edge during the optimization process, but it seems that the output stream like std::cout/std::cerr doesn't work in the computeError(). I have tried the write(ostream &os) function but it is used for save information in a file. I want to see some information in real-time because there is a unknown bug which will cause the system crashing. Do you know the solution? Thank you.

@RainerKuemmerle
Copy link
Owner

Do you have a minimal working example that illustrates the problem?
Using cout/cerr should work as expected. In the g2o_viewer cerr is redirected to the GUI and you should see the output there instead of on the console.

About the crash:
Does gdb provide insights? Or tools like valgrind?

@yangliu9527
Copy link
Author

yangliu9527 commented Feb 7, 2024

I have solved the crash bug but the printing problem still exists. Here is an example of working computeError() function, where both the
cout << error << endl;
cout << "x="<<proj_x<<", y="<<proj_y<<endl; don't work. Do you have any solution? Thank you.

void EdgeLaneAlignOnlyPose::computeError()
{
const g2o::VertexSE3Expmap *v1 = static_cast<const g2o::VertexSE3Expmap *>(_vertices[0]);
Eigen::Vector2d proj_p = pCamera->project(v1->estimate().map(Pw));
double proj_x = proj_p[0];
double proj_y = proj_p[1];
cout << "x="<<proj_x<<", y="<<proj_y<<endl;
if (proj_x <= 1 || proj_x >= (pImEdgeDT->cols - 1) || proj_y <= 1 || proj_y >= (pImEdgeDT->rows - 1))
{
setLevel(1);
_error.setZero();
return;
}
else
{
// double error = static_cast(pImEdgeDT->ptr(proj_y)[proj_x]);
double error = static_cast(Utility::GetPixelValue(pImEdgeDT, proj_x, proj_y));
cout << error <<endl;
_error(0, 0) = error;
}
}

@RainerKuemmerle
Copy link
Owner

Try to use a debugger along with a breakpoint in the respective functions. Without a minimal working example, I cannot tell what is going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants