*/
#include <DecodeInfo.h>
+#include <Utils.h>
using namespace mediavision::inference;
using namespace mediavision::inference::box;
anchorParam.mode = static_cast<int>(json_object_get_int_member(object, "mode"));
- anchorParam.numLayers = static_cast<int>(json_object_get_int_member(object, "num_layers"));
- anchorParam.minScale = static_cast<float>(json_object_get_double_member(object, "min_scale"));
- anchorParam.maxScale = static_cast<float>(json_object_get_double_member(object, "max_scale"));
+ if (anchorParam.mode == 0) { // SSD
+ anchorParam.numLayers = static_cast<int>(json_object_get_int_member(object, "num_layers"));
+
+ anchorParam.minScale = static_cast<float>(json_object_get_double_member(object, "min_scale"));
+ anchorParam.maxScale = static_cast<float>(json_object_get_double_member(object, "max_scale"));
+
+ anchorParam.isReduceBoxedInLowestLayer =
+ static_cast<bool>(json_object_get_boolean_member(object, "reduce_boxed_in_lowest_layer"));
+ anchorParam.interpolatedScaleAspectRatio =
+ static_cast<float>(json_object_get_double_member(object, "interpolated_scale_aspect_ratio"));
+ anchorParam.isFixedAnchorSize = static_cast<bool>(json_object_get_boolean_member(object, "fixed_anchor_size"));
+ anchorParam.isExponentialBoxScale =
+ static_cast<bool>(json_object_get_boolean_member(object, "exponential_box_scale"));
+
+ anchorParam.xScale = static_cast<float>(json_object_get_double_member(object, "x_scale"));
+ anchorParam.yScale = static_cast<float>(json_object_get_double_member(object, "y_scale"));
+ anchorParam.wScale = static_cast<float>(json_object_get_double_member(object, "w_scale"));
+ anchorParam.hScale = static_cast<float>(json_object_get_double_member(object, "h_scale"));
+
+ JsonArray *array = json_object_get_array_member(object, "aspect_ratios");
+ auto elements = json_array_get_length(array);
+ for (unsigned int elem2 = 0; elem2 < elements; ++elem2) {
+ auto aspectRatio = static_cast<float>(json_array_get_double_element(array, elem2));
+ anchorParam.aspectRatios.push_back(aspectRatio);
+ LOGI("aspectRatio: %.4f", aspectRatio);
+ }
+ } else if (anchorParam.mode == 1) { // Yolo
+ anchorParam.numAnchorsPerCell = static_cast<int>(json_object_get_int_member(object, "num_anchors"));
+
+ anchorParam.offsetAnchors = static_cast<int>(json_object_get_int_member(object, "offset_anchors"));
+ JsonArray *xScales = json_object_get_array_member(object, "x_scales");
+ JsonArray *yScales = json_object_get_array_member(object, "y_scales");
+ unsigned int xElements2 = json_array_get_length(xScales);
+ unsigned int yElements2 = json_array_get_length(yScales);
+ if (xElements2 != yElements2) {
+ LOGE("Invalid x and y scales. They should be the same size");
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
+ for (unsigned int elem2 = 0; elem2 < xElements2; ++elem2) {
+ JsonArray *xArray = json_array_get_array_element(xScales, elem2);
+ JsonArray *yArray = json_array_get_array_element(yScales, elem2);
+ unsigned int xArrayElements2 = json_array_get_length(xArray);
+ unsigned int yArrayElements2 = json_array_get_length(yArray);
+ if (xArrayElements2 != yArrayElements2) {
+ LOGE("Invalid x and y scales. They should be the same size");
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+ std::vector<double> xScale_;
+ std::vector<double> yScale_;
+ for (unsigned int arrayElem2 = 0; arrayElem2 < xArrayElements2; ++arrayElem2) {
+ auto xScale = static_cast<double>(json_array_get_double_element(xArray, arrayElem2));
+ auto yScale = static_cast<double>(json_array_get_double_element(yArray, arrayElem2));
+ LOGI("xScale:%lf, yScale:%lf", xScale, yScale);
+ xScale_.push_back(xScale);
+ yScale_.push_back(yScale);
+ }
+ anchorParam.vxScales.push_back(xScale_);
+ anchorParam.vyScales.push_back(yScale_);
+ }
+ } else {
+ LOGE("Invalid anchor mode [%d]", anchorParam.mode);
+ return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+ }
+
anchorParam.inputSizeHeight = static_cast<int>(json_object_get_int_member(object, "input_size_height"));
anchorParam.inputSizeWidth = static_cast<int>(json_object_get_int_member(object, "input_size_width"));
anchorParam.anchorOffsetX = static_cast<float>(json_object_get_double_member(object, "anchor_offset_x"));
anchorParam.anchorOffsetY = static_cast<float>(json_object_get_double_member(object, "anchor_offset_y"));
- anchorParam.isReduceBoxedInLowestLayer =
- static_cast<bool>(json_object_get_boolean_member(object, "reduce_boxed_in_lowest_layer"));
- anchorParam.interpolatedScaleAspectRatio =
- static_cast<float>(json_object_get_double_member(object, "interpolated_scale_aspect_ratio"));
- anchorParam.isFixedAnchorSize = static_cast<bool>(json_object_get_boolean_member(object, "fixed_anchor_size"));
- anchorParam.isExponentialBoxScale =
- static_cast<bool>(json_object_get_boolean_member(object, "exponential_box_scale"));
-
- anchorParam.xScale = static_cast<float>(json_object_get_double_member(object, "x_scale"));
- anchorParam.yScale = static_cast<float>(json_object_get_double_member(object, "y_scale"));
- anchorParam.wScale = static_cast<float>(json_object_get_double_member(object, "w_scale"));
- anchorParam.hScale = static_cast<float>(json_object_get_double_member(object, "h_scale"));
JsonArray *array = json_object_get_array_member(object, "strides");
unsigned int elements2 = json_array_get_length(array);
LOGI("stride: %d", stride);
}
- array = json_object_get_array_member(object, "aspect_ratios");
- elements2 = json_array_get_length(array);
- for (unsigned int elem2 = 0; elem2 < elements2; ++elem2) {
- auto aspectRatio = static_cast<float>(json_array_get_double_element(array, elem2));
- anchorParam.aspectRatios.push_back(aspectRatio);
- LOGI("aspectRatio: %.4f", aspectRatio);
- }
-
return MEDIA_VISION_ERROR_NONE;
}