xdspacelab / openvslam

OpenVSLAM: A Versatile Visual SLAM Framework
https://openvslam.readthedocs.io/
2.97k stars 869 forks source link

why load dbow2 file cast very long time (few minutes) on iphone xs Max? #91

Open taontech opened 5 years ago

taontech commented 5 years ago

loadFromBinaryFile method cast very long time, I don't know where is the problem .

shinsumicco commented 5 years ago

Could you tell me the behavior in detail?

riematrix commented 5 years ago

If load binary vocabulary is slow, the cause maybe DBoW2's loadFromBinaryFile method in TemplatedVocabulary.h.

You may notice one line: m_nodes.at(n_id).descriptor = cv::Mat(1, F::L, CV_8U); which lies in a while loop. Usually the quantity of words is large. Meanwhile the cv::Mat constructor may trigger reallocate which sometimes can be slow.

The solution is create a sufficiently large cv::Mat outside the loop, and assign one row to m_nodes's descriptor each time accordingly, i.e.

m_nodes.at(n_id).descriptor = yourMat.row(row_index)

Dylanooo commented 4 years ago

I have the same problem,especially with iOS 13

shinsumicco commented 4 years ago

@taontech @riematrix @Dylanooo Thanks for reporting. We'll fix DBoW2 according to the solution provided by @riematrix.

adelpit commented 3 years ago

I have a PR that fixed this issue for me in case anyone is interested

https://github.com/shinsumicco/DBoW2/pull/8