-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhw2.cpp
More file actions
61 lines (48 loc) · 1.81 KB
/
Copy pathhw2.cpp
File metadata and controls
61 lines (48 loc) · 1.81 KB
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
#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
#include <chrono>
#include "image.hpp"
#include "sift.hpp"
int main(int argc, char *argv[])
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
if (argc != 4) {
std::cerr << "Usage: ./hw2 ./testcases/xx.jpg ./results/xx.jpg ./results/xx.txt\n";
return 1;
}
std::string input_img = argv[1];
std::string output_img = argv[2];
std::string output_txt = argv[3];
auto start = std::chrono::high_resolution_clock::now();
Image img(input_img);
img = img.channels == 1 ? img : rgb_to_grayscale(img);
std::vector<Keypoint> kps = find_keypoints_and_descriptors(img);
/////////////////////////////////////////////////////////////
// The following code is for the validation
// You can not change the logic of the following code, because it is used for judge system
std::ofstream ofs(output_txt);
if (!ofs) {
std::cerr << "Failed to open " << output_txt << " for writing.\n";
} else {
ofs << kps.size() << "\n";
for (const auto& kp : kps) {
ofs << kp.i << " " << kp.j << " " << kp.octave << " " << kp.scale << " ";
for (size_t i = 0; i < kp.descriptor.size(); ++i) {
ofs << " " << static_cast<int>(kp.descriptor[i]);
}
ofs << "\n";
}
ofs.close();
}
Image result = draw_keypoints(img, kps);
result.save(output_img);
/////////////////////////////////////////////////////////////
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> duration = end - start;
std::cout << "Execution time: " << duration.count() << " ms\n";
std::cout << "Found " << kps.size() << " keypoints.\n";
return 0;
}