MarvinChung / Orbeez-SLAM

GNU General Public License v3.0
264 stars 29 forks source link

About g2o in the project #7

Open HJMGARMIN opened 1 year ago

HJMGARMIN commented 1 year ago

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 commented 1 year ago

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: https://github.com/MarvinChung/Orbeez-SLAM/blob/5298376a0e35ec3bcdb5383b6b4ea71648336c8f/src/Optimizer.cu#L77-L79

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 commented 1 year ago

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 commented 1 year ago

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 commented 4 months ago

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.