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

About g2o in the project #7

Open
HJMGARMIN opened this issue Aug 10, 2023 · 4 comments
Open

About g2o in the project #7

HJMGARMIN opened this issue Aug 10, 2023 · 4 comments

Comments

@HJMGARMIN
Copy link

Hello, thanks for your great work!
Now, I want to combine ORB-SLAM3 and instant-ngp. However, the project aborted in the function of PoseOptimization. I found that the g2o library in Orbeez-SLAM is different from original ORB-SLAM2. Why do not you use the g2o library of original ORB-SLAM2?
I link the libg2o.so of ORB-SLAM3 in the same way as libDBoW2.go. I think the problem is caused by g2o. But I do not know how to fix it.

@MarvinChung
Copy link
Owner

MarvinChung commented Aug 11, 2023

Hi, I kind of forgot the reason, but I believe it's because the new version of g2o uses smart pointers in its code. I've also implemented it in some of the code. You can find an example here:

std::unique_ptr<g2o::BlockSolver_6_3::LinearSolverType> linearSolver(new g2o::LinearSolverEigen<g2o::BlockSolver_6_3::PoseMatrixType>());
std::unique_ptr<g2o::BlockSolver_6_3> solver_ptr( new g2o::BlockSolver_6_3( std::move(linearSolver)));
g2o::OptimizationAlgorithmLevenberg *solver = new g2o::OptimizationAlgorithmLevenberg( std::move(solver_ptr));

Using smart pointers can help prevent memory leaks, especially in optimization processes where you might create numerous new vertices and edges, potentially consuming a significant amount of memory. I can't recall whether the older g2o library would lead to a program crash, but I suspect that this could be the reason behind the issue with ORB-SLAM3 + instant-ngp crashing during the PoseOptimization function.

@HJMGARMIN
Copy link
Author

HJMGARMIN commented Aug 12, 2023

Thanks for your reply. I will try the new version of g2o later.
I have another question about System.cu as follows:

void to_json(nlohmann::json& j, const SLAMCameraKeyFrame& p) {
    j = nlohmann::json{{"R", p.R}, {"T", p.T}, {"slice", p.slice}, {"scale", p.scale}, {"fov", p.fov}, {"dof", p.dof}};
}

// Use for Trajectory
void to_json(nlohmann::json& j, const Trajectory& p) {
    j = nlohmann::json{{"timestamp", p.timestamp}, {"quat", p.quat}, {"t", p.t}};
}

These code will cause the problem when I use the g2o of ORB-SLAM3:

没有与参数列表匹配的构造函数 "nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::basic_json [其中 ObjectType=std::map, ArrayType=std::vector, StringType=std::__cxx11::string, BooleanType=bool, NumberIntegerType=int64_t, NumberUnsignedType=uint64_t, NumberFloatType=double, AllocatorType=std::allocator, JSONSerializer=nlohmann::adl_serializer, BinaryType=std::vector<uchar, std::allocator>]" 实例C/C++(289)
System.cu(1284, 23): 参数类型为: ({...}, {...}, {...}, {...}, {...}, {...})
using nlohmann::json = nlohmann::basic_json<>
namespace for Niels Lohmann

@MarvinChung
Copy link
Owner

My project is able to use nlohmann because it is under my Thirdparty (instant-ngp-kf -> dependencies -> tiny_cuda_nn -> dependencies -> json)

https://github.com/NVlabs/tiny-cuda-nn/tree/4e0905311f1245c60b9fcc3a1c271ebb0ba50218/dependencies/json

You may need to add it to your Thirdparty and modify your CMakeLists.txt.

@Augusthyq
Copy link

Hello, thanks for your great work! Now, I want to combine ORB-SLAM3 and instant-ngp. However, the project aborted in the function of PoseOptimization. I found that the g2o library in Orbeez-SLAM is different from original ORB-SLAM2. Why do not you use the g2o library of original ORB-SLAM2? I link the libg2o.so of ORB-SLAM3 in the same way as libDBoW2.go. I think the problem is caused by g2o. But I do not know how to fix it.

Hello, have you successfully combined ORB-SLAM3 and instant-ngp? Thank you very much for your reply.

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

3 participants