-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.cpp
47 lines (44 loc) · 1.19 KB
/
example.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
#include <iostream>
#include <fstream>
#include <format>
#include "nms.hpp"
std::vector<std::vector<float>> read_boxes(const std::string& filename)
{
std::vector<std::vector<float>> boxes;
std::ifstream file(filename);
if (!file.is_open())
{
std::cout << "file open failed" << std::endl;
return boxes;
}
while (!file.eof())
{
std::vector<float> box;
float x1, y1, x2, y2, score, class_id;
file >> x1 >> y1 >> x2 >> y2 >> score >> class_id;
boxes.push_back({x1, y1, x2, y2, score, class_id});
}
file.close();
return boxes;
}
void write_boxes(const std::string& filename, const std::vector<std::vector<float>>& boxes)
{
std::ofstream file(filename);
if (!file.is_open())
{
std::cout << "file open failed" << std::endl;
return;
}
for (auto box : boxes) // Do you feel uncomfortable? Do you want to use for_each?
{
file << std::format("{} {} {} {} {} {}\n", box[0], box[1], box[2], box[3], box[4], box[5]);
}
file.close();
}
int main()
{
std::vector<std::vector<float>> boxes = read_boxes("boxes.txt");
nms(boxes);
write_boxes("boxes_nms.txt", boxes);
return 0;
}