1+ #include < opencv2/core/types.hpp>
2+ #include < StringSLAM/Tracker/MonoTracker.hpp>
3+ #include < StringSLAM/Features/KeypointExtractor.hpp>
4+ #include < StringSLAM/Features/DescriptorMatcher.hpp>
5+ #include < StringSLAM/core.hpp>
6+ #include < opencv2/highgui.hpp>
7+ #include < opencv4/opencv2/features2d.hpp>
8+ #include < deque>
9+
10+ using namespace StringSLAM ;
11+
12+ int main () {
13+ std::shared_ptr<Tracker::MonoTracker> mt1 = Tracker::MonoTracker::create (0 , CameraModel ());
14+
15+ std::shared_ptr<Accelerator> accelerator = Accelerator::create ();
16+ accelerator->createGPU (true , 10 );
17+
18+ std::shared_ptr<OrbWrapper> orb = OrbWrapper::create (800 , 1 .2f , 4 , 30 , 0 , 2 , cv::ORB::HARRIS_SCORE, 32 , 30 );
19+ std::shared_ptr<Features::KeypointExtractor> kpExtractor = Features::KeypointExtractor::create (orb);
20+ std::shared_ptr<Features::DescriptorMatcher> descMatcher = Features::DescriptorMatcher::create (orb);
21+
22+ mt1->open ();
23+
24+ std::vector<cv::DMatch> matches;
25+ std::deque<Frame> frames;
26+ Frame tempFrame, prevFrame;
27+ cv::Mat out;
28+
29+ for (;;) {
30+ // If the frame list isn't empty then get prev frame.
31+ if (!frames.empty ()) prevFrame = frames.back ();
32+
33+ // Read frame from camera
34+ mt1->read (tempFrame);
35+ out = tempFrame.frame ;
36+
37+ // Get keypoints
38+ kpExtractor->getKeypoints (tempFrame);
39+ if (!prevFrame.kp .empty ()) {
40+ // Get matches for keypoints and generator descriptor
41+ matches = descMatcher->matchFramesLK (tempFrame, prevFrame);
42+
43+ // Draw matches
44+ if (!matches.empty ()) descMatcher->drawMatches (tempFrame, prevFrame, matches, out);
45+ }
46+
47+ cv::imshow (" Viewer" , out);
48+ cv::waitKey (mt1->getFPS ());
49+
50+ // Only add frame if it has keypoints
51+ if (!tempFrame.kp .empty ())
52+ frames.push_back (tempFrame);
53+
54+ // If more than 45 frame remove the first one
55+ if (frames.size () > 45 )
56+ frames.pop_front ();
57+ }
58+ }
0 commit comments