feature(demo) Support rectangle image in yolox_openvino.cpp (#546)
Browse files
demo/OpenVINO/cpp/yolox_openvino.cpp
CHANGED
@@ -32,7 +32,8 @@ cv::Mat static_resize(cv::Mat& img) {
|
|
32 |
int unpad_h = r * img.rows;
|
33 |
cv::Mat re(unpad_h, unpad_w, CV_8UC3);
|
34 |
cv::resize(img, re, re.size());
|
35 |
-
cv::Mat out(INPUT_W, INPUT_H, CV_8UC3, cv::Scalar(114, 114, 114));
|
|
|
36 |
re.copyTo(out(cv::Rect(0, 0, re.cols, re.rows)));
|
37 |
return out;
|
38 |
}
|
@@ -80,14 +81,15 @@ struct GridAndStride
|
|
80 |
int stride;
|
81 |
};
|
82 |
|
83 |
-
static void generate_grids_and_stride(const int
|
84 |
{
|
85 |
for (auto stride : strides)
|
86 |
{
|
87 |
-
int
|
88 |
-
|
|
|
89 |
{
|
90 |
-
for (int g0 = 0; g0 <
|
91 |
{
|
92 |
grid_strides.push_back((GridAndStride){g0, g1, stride});
|
93 |
}
|
@@ -234,7 +236,7 @@ static void decode_outputs(const float* prob, std::vector<Object>& objects, floa
|
|
234 |
std::vector<int> strides = {8, 16, 32};
|
235 |
std::vector<GridAndStride> grid_strides;
|
236 |
|
237 |
-
generate_grids_and_stride(INPUT_W, strides, grid_strides);
|
238 |
generate_yolox_proposals(grid_strides, prob, BBOX_CONF_THRESH, proposals);
|
239 |
qsort_descent_inplace(proposals);
|
240 |
|
|
|
32 |
int unpad_h = r * img.rows;
|
33 |
cv::Mat re(unpad_h, unpad_w, CV_8UC3);
|
34 |
cv::resize(img, re, re.size());
|
35 |
+
//cv::Mat out(INPUT_W, INPUT_H, CV_8UC3, cv::Scalar(114, 114, 114));
|
36 |
+
cv::Mat out(INPUT_H, INPUT_W, CV_8UC3, cv::Scalar(114, 114, 114));
|
37 |
re.copyTo(out(cv::Rect(0, 0, re.cols, re.rows)));
|
38 |
return out;
|
39 |
}
|
|
|
81 |
int stride;
|
82 |
};
|
83 |
|
84 |
+
static void generate_grids_and_stride(const int target_w, const int target_h, std::vector<int>& strides, std::vector<GridAndStride>& grid_strides)
|
85 |
{
|
86 |
for (auto stride : strides)
|
87 |
{
|
88 |
+
int num_grid_w = target_w / stride;
|
89 |
+
int num_grid_h = target_h / stride;
|
90 |
+
for (int g1 = 0; g1 < num_grid_h; g1++)
|
91 |
{
|
92 |
+
for (int g0 = 0; g0 < num_grid_w; g0++)
|
93 |
{
|
94 |
grid_strides.push_back((GridAndStride){g0, g1, stride});
|
95 |
}
|
|
|
236 |
std::vector<int> strides = {8, 16, 32};
|
237 |
std::vector<GridAndStride> grid_strides;
|
238 |
|
239 |
+
generate_grids_and_stride(INPUT_W, INPUT_H, strides, grid_strides);
|
240 |
generate_yolox_proposals(grid_strides, prob, BBOX_CONF_THRESH, proposals);
|
241 |
qsort_descent_inplace(proposals);
|
242 |
|