31bool LoadAnchors(
const std::string &path, std::vector<float> *anchors) {
33 std::ifstream ifs(path, std::ifstream::in);
36 AERROR <<
"Failed to get number of anchors!";
39 (*anchors).resize(num_anchors * 2);
40 for (
int i = 0; i < num_anchors; ++i) {
41 ifs >> (*anchors)[i * 2] >> (*anchors)[i * 2 + 1];
43 AERROR <<
"Failed to load the " << i <<
"-th anchor!";
90 int width = dst_blob->shape(2);
91 int height = dst_blob->shape(1);
92 int channel = dst_blob->shape(3);
93 int origin_channel = src_blob.
shape(3);
94 int origin_height = src_blob.
shape(1);
95 int origin_width = src_blob.
shape(2);
96 if (origin_channel != dst_blob->shape(3)) {
97 AERROR <<
"channel should be the same after resize.";
100 float fx =
static_cast<float>(origin_width) /
static_cast<float>(width);
101 float fy =
static_cast<float>(origin_height) /
static_cast<float>(height);
103 auto dst = dst_blob->mutable_cpu_data();
104 for (
int dst_y = 0; dst_y < height; dst_y++) {
105 for (
int dst_x = 0; dst_x < width; dst_x++) {
106 float src_x = (
static_cast<float>(dst_x) + 0.5f) * fx - 0.5f;
107 float src_y = (
static_cast<float>(dst_y) + 0.5f) * fy - 0.5f;
108 const int x1 =
static_cast<int>(src_x + 0.5);
109 const int y1 =
static_cast<int>(src_y + 0.5);
110 const int x1_read = std::max(x1, 0);
111 const int y1_read = std::max(y1, 0);
112 const int x2 = x1 + 1;
113 const int y2 = y1 + 1;
114 const int x2_read = std::min(x2, width - 1);
115 const int y2_read = std::min(y2, height - 1);
117 for (
int c = 0; c < channel; c++) {
120 int idx11 = (y1_read * stepwidth + x1_read) * channel;
121 src_reg = src[idx11 + c];
122 out = out + (
static_cast<float>(x2) - src_x) *
123 (
static_cast<float>(y2) - src_y) *
124 static_cast<float>(src_reg);
125 int idx12 = (y1_read * stepwidth + x2_read) * channel;
126 src_reg = src[idx12 + c];
127 out = out +
static_cast<float>(src_reg) *
128 (src_x -
static_cast<float>(x1)) *
129 (
static_cast<float>(y2) - src_y);
131 int idx21 = (y2_read * stepwidth + x1_read) * channel;
132 src_reg = src[idx21 + c];
133 out = out +
static_cast<float>(src_reg) *
134 (
static_cast<float>(x2) - src_x) *
135 (src_y -
static_cast<float>(y1));
137 int idx22 = (y2_read * stepwidth + x2_read) * channel;
138 src_reg = src[idx22 + c];
139 out = out +
static_cast<float>(src_reg) *
140 (src_x -
static_cast<float>(x1)) *
141 (src_y -
static_cast<float>(y1));
148 int dst_idx = (dst_y * width + dst_x) * channel + c;
161 const double length = object_ptr->
size(0);
162 const double width = object_ptr->
size(1);
164 double x1 = length / 2;
166 double y1 = width / 2;
170 double cos_theta = object_ptr->
direction[0] / len;
171 double sin_theta = -object_ptr->
direction[1] / len;
175 x1 * cos_theta + y1 * sin_theta + object_ptr->
center[0];
177 y1 * cos_theta - x1 * sin_theta + object_ptr->
center[1];
178 object_ptr->
polygon[0].z = 0.0;
181 x1 * cos_theta + y2 * sin_theta + object_ptr->
center[0];
183 y2 * cos_theta - x1 * sin_theta + object_ptr->
center[1];
184 object_ptr->
polygon[1].z = 0.0;
187 x2 * cos_theta + y2 * sin_theta + object_ptr->
center[0];
189 y2 * cos_theta - x2 * sin_theta + object_ptr->
center[1];
190 object_ptr->
polygon[2].z = 0.0;
193 x2 * cos_theta + y1 * sin_theta + object_ptr->
center[0];
195 y1 * cos_theta - x2 * sin_theta + object_ptr->
center[1];
196 object_ptr->
polygon[3].z = 0.0;