-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
I managed to get the program running on a modern Gentoo system with a monocular USB camera. It's noticeable that the program is buggy during initialization, in my opinion, but this was necessary. With this camera (Rollei R-Cam 100), bool TwoViewReconstruction::ReconstructF is called, where the following code change is made: `minParallax = 0.f;
if(maxGood<nMinGood || nsimilar>3)//1)and this inTracking.cc if(!mbReadyToInitialize) { ... ... return MonocularInitialization(); }- after that, it worked :) - this should help anyone trying it with a monocular camera. [edit] Whilereturn MonocularInitialization();is not necessary (but possible), the biggest error seems to be thatminParallaxis defined as 1.0 (it should probably bemaxParallax? I haven't analyzed the code enough to be sure), and the pics from my cam always gets a value of 2 for nsimilar`, which is why it was never initialized.
I'm writing this because I thought my system was missing libraries and I spent hours searching for connections until I analyzed the code, and I believe that this probably doesn't only apply to this camera (although I also don't understand why ffmpeg should be necessary on Ubuntu; OpenCV on my system isn't able to work with the ffmpeg backend, only GStreamer and V4L).
Aside from that, it was of course necessary to modify the CMakeLists.txt file for it to compile at all. Then, somewhere in the program, an int is defined as a bool (you notice that immediately with a modern compiler) (but the purpose of the int/bool isn't clear anyway). There's a more modern branch that compiles without modifications (https://github.com/devansh0703/ORB_SLAM3.git), but even with the changes mentioned above, this code didn't work for me(I don't know why yet).
For those interested, this is my test code (comments are in German).
#include
#include <opencv2/opencv.hpp>
#include "../include/System.h" // Pfad zu ORB_SLAM3/System.h anpassen
int main(int argc, char** argv) {
// Prüfen, ob die erforderlichen Dateien angegeben sind
if (argc < 3) {
std::cerr << "Usage: " << argv[0] << " ORBvoc.txt Camera.yaml [camera_id]" << std::endl;
return -1;
}
std::string vocab_path = argv[1];
std::string settings_path = argv[2];
int cam_id = 0; // Standard‑Kamera‑ID
if (argc >= 4) cam_id = std::stoi(argv[3]);
// ORB_SLAM3‑System initialisieren
ORB_SLAM3::System SLAM(vocab_path, settings_path, ORB_SLAM3::System::MONOCULAR, 1);
// OpenCV VideoCapture öffnen
cv::VideoCapture cap(cam_id);//, cv::CAP_FFMPEG); cv::CAP_V4L2);
bool b= cap.set(cv::CAP_PROP_FRAME_WIDTH, 640.);
b= cap.set(cv::CAP_PROP_FRAME_HEIGHT, 480.);
cap.set(cv::CAP_PROP_FPS, 25.);
if (!cap.isOpened()) {
std::cerr << "Fehler: Konnte Kamera " << cam_id << " nicht öffnen!" << std::endl;
return -1;
}
// Haupt‑Loop: Bild einlesen, SLAM‑Tracking aufrufen
cv::Mat frame, frame2;
while (true) {
cap >> frame; // Bild von der Kamera lesen
if (!frame.empty()){//cap.read(frame)) {
// Zeitstempel (z. B. cv::getTickCount)
double timestamp = static_cast(cv::getTickCount()) / cv::getTickFrequency();
SLAM.TrackMonocular(frame, timestamp);
}
if (0) // It might be better to copy the frame (frame2 = frame)
cv::imshow("Live Feed", frame);
//A key break check should be implemented here.
}
// Beenden
SLAM.Shutdown();
//SLAM.SaveTrajectory("trajectory.txt"); // Trajektorie speichern
SLAM.SaveTrajectoryEuRoC("trajectory.txt");
return 0;
}