-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathboxes.cpp
More file actions
40 lines (40 loc) · 1.46 KB
/
Copy pathboxes.cpp
File metadata and controls
40 lines (40 loc) · 1.46 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
#include "boxes.hpp"
namespace la {
static constexpr int COORD_START=151677, COORD_END=152677,
BOX_START=151668, BOX_END=151669, REF_START=151672, REF_END=151673;
std::vector<Box> parse_boxes(const std::vector<int32_t>& ids, int img_w, int img_h,
const std::function<std::string(const std::vector<int32_t>&)>& decode_label){
std::vector<Box> out;
std::string cur_label;
int i=0, n=(int)ids.size();
while(i<n){
int t=ids[i];
if(t==REF_START){
int j=i+1; std::vector<int32_t> label_ids;
while(j<n && ids[j]!=REF_END){
label_ids.push_back(ids[j]);
++j;
}
cur_label = decode_label(label_ids); // byte-decode the vocab pieces
i=j+1; continue; // label persists until next REF_START
}
if(t==BOX_START){
int j=i+1; std::vector<int> coords;
while(j<n && ids[j]!=BOX_END){
if(ids[j]>=COORD_START && ids[j]<=COORD_END) coords.push_back(ids[j]-COORD_START);
++j;
}
if(coords.size()==4){
Box b;
b.x1 = coords[0]/1000.f*img_w; b.y1 = coords[1]/1000.f*img_h;
b.x2 = coords[2]/1000.f*img_w; b.y2 = coords[3]/1000.f*img_h;
b.label = cur_label;
out.push_back(b);
}
i=j+1; continue;
}
++i;
}
return out;
}
}