forked from ChanWoo25/SuperPoint2CPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_SuperPoint.cpp
84 lines (64 loc) · 2.61 KB
/
main_SuperPoint.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <SPDetector.hpp>
#include <Tools.hpp>
using namespace SuperPointSLAM;
/** You need to modify the path below that corresponds to your dataset and weight path. **/
const std::string weight_dir = "./Weights/superpoint.pt";
void test();
int main(const int argc, char* argv[])
{
/** From the main argument, Retrieve waiting period to control Displaying.**/
int ms;
if(argc == 2)
{
char* a = argv[1];
ms = std::atoi(a);
}
else ms = 100;
std::cout << "Frame rate is " << ms << "ms.\n";
/** Initialize VideoSteamer and SuperPoint Object **/
// VideoStreamer vs("../Dataset/nyu_snippet.mp4");
VideoStreamer vs(0);
// VideoStreamer vs(kitti_dir);
// vs.setImageSize(cv::Size(720, 240));
/** Superpoint Detector **/
SPDetector SPF(weight_dir, torch::cuda::is_available());
std::cout << "VC created, SPDetector Constructed.\n";
// Test input/output file
// std::ifstream inputFile("input.txt", std::ios::in);
// std::ofstream outputFile("output.txt", std::ios::out | std::ios::app);
// int test_nms_dist_thres;
// float test_conf_thres;
// inputFile >> test_nms_dist_thres >> test_conf_thres;
cv::namedWindow("superpoint", cv::WINDOW_AUTOSIZE);
long long idx=0;
while(++idx){
// Capture frame-by-frame
// Image's size is [640 x 480]
if(!vs.next_frame()) { std::cout << "main -- Video End\n"; break; }
std::vector<cv::KeyPoint> Keypoints;
cv::Mat Descriptors;
auto start = std::chrono::system_clock::now();
SPF.detect(vs.input, Keypoints, Descriptors);
auto end = std::chrono::system_clock::now();
std::chrono::milliseconds mill = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
/* Logging */
std::cout << idx << "th ProcessTime: " << mill.count() << "ms\n";
std::cout << "Keypoint num: " << Keypoints.size() << std::endl;
/* Visualization */
float x_scale(vs.W_scale), y_scale(vs.H_scale);
auto kpt_iter = Keypoints.begin();
for(; kpt_iter != Keypoints.end(); kpt_iter++)
{
float X(kpt_iter->pt.x), Y(kpt_iter->pt.y);
double conf(kpt_iter->response);
cv::circle(vs.img, cv::Point(int(X*x_scale), int(Y*y_scale)), 1, cv::Scalar(0, 0, (255 * conf * 10)), 2);
}
/* Display the resulting frame */
cv::imshow( "superpoint", vs.img );
// Press ESC on keyboard to exit
char c = (char)cv::waitKey(ms);
if(c==27){ break; }
}
// Closes all the frames
cv::destroyAllWindows();
}