auto context = static_cast<Context *>(handle);
auto task = static_cast<ObjectDetectionTask *>(context->__tasks["objectron"]);
- object_detection_3d_result_s *result = task->getOutput();
+ object_detection_3d_result_s& result = task->getOutput();
- *out_probability = result->probability;
+ *out_probability = result.probability;
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
auto context = static_cast<Context *>(handle);
auto task = static_cast<ObjectDetectionTask *>(context->__tasks["objectron"]);
- auto result = task->getOutput();
+ object_detection_3d_result_s& result = task->getOutput();
- *out_num_of_points = result->number_of_points;
+ *out_num_of_points = result.number_of_points;
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
Context *context = static_cast<Context *>(handle);
auto task = static_cast<ObjectDetectionTask *>(context->__tasks["objectron"]);
- auto result = task->getOutput();
+ object_detection_3d_result_s& result = task->getOutput();
- *out_x = result->x_points;
- *out_y = result->y_points;
+ *out_x = result.x_vec.data();
+ *out_y = result.y_vec.data();
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
namespace machine_learning
{
-Objectron::Objectron()
+Objectron::Objectron() : _result()
{
_inference = make_unique<Inference>();
- _result = make_unique<object_detection_3d_result_s>();
}
Objectron::~Objectron()
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to get target device type.");
- ret = _config->getIntegerAttribute(string(MV_OBJECT_DETECTION_3D_MAX_NUM_OF_POINTS),
- &_maxPoints);
- if (ret != MEDIA_VISION_ERROR_NONE)
- throw InvalidOperation("Fail to get maximum number of points.");
-
- ret = _config->getIntegerAttribute(string(MV_OBJECT_DETECTION_3D_MAX_NUM_OF_EDGES),
- &_maxEdges);
- if (ret != MEDIA_VISION_ERROR_NONE)
- throw InvalidOperation("Fail to get maximum number of edges.");
-
ret = _config->getStringAttribute(MV_OBJECT_DETECTION_3D_MODEL_FILE_PATH, &_modelFilePath);
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to get model file path");
ret = _inference->ParseMetadata(_modelMetaFilePath);
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to ParseMetadata");
-
- if (!_result->x_points) {
- _result->x_points = new (nothrow) unsigned int[_maxPoints];
- if (!_result->x_points)
- throw InvalidOperation("Fail to allocate x edges");
- }
-
- if (!_result->y_points) {
- _result->y_points = new (nothrow) unsigned int[_maxPoints];
- if (!_result->y_points) {
- delete []_result->x_points;
- throw InvalidOperation("Fail to allocate y edges");
- }
- }
-
- if (!_result->edge_indexes) {
- _result->edge_indexes = new (nothrow) edge_index_s[_maxEdges];
- if (!_result->edge_indexes) {
- delete []_result->y_points;
- delete []_result->x_points;
- throw InvalidOperation("Fail to allocate edge indexes");
- }
- }
}
-object_detection_3d_result_s* Objectron::getResult()
+object_detection_3d_result_s& Objectron::getResult()
{
TensorBuffer& tensor_buffer_obj = _inference->GetOutputTensorBuffer();
IETensorBuffer &ie_tensor_buffer = tensor_buffer_obj.getIETensorBuffer();
if (output_size != 18)
throw InvalidOperation("Invalid number of points. Number of points should be 18.");
- unsigned int result_idx = 0;
-
float x_scale = static_cast<float>(_inference->getSourceWidth()) / static_cast<float>(_inference->getInputWidth());
float y_scale = static_cast<float>(_inference->getSourceHeight()) / static_cast<float>(_inference->getInputHeight());
+ _result.x_vec.clear();
+ _result.y_vec.clear();
+
for (unsigned int idx = 0; idx < output_size; idx += 2) {
- _result->x_points[result_idx] = static_cast<int>(keypoints[idx] * x_scale);
- _result->y_points[result_idx++] = static_cast<int>(keypoints[idx + 1] * y_scale);
+ _result.x_vec.push_back(static_cast<int>(keypoints[idx] * x_scale));
+ _result.y_vec.push_back(static_cast<int>(keypoints[idx + 1] * y_scale));
}
- _result->number_of_points = output_size / 2;
+ _result.number_of_points = output_size / 2;
string& identity_layer = output_layer_names[0];
throw InvalidOperation("Fail to get tensor buffer.");
auto *prob = reinterpret_cast<float *>(tensor_buffer->buffer);
- _result->probability = static_cast<unsigned int>(prob[0] * 100);
- _result->number_of_edges = _maxEdges;
+ _result.probability = static_cast<unsigned int>(prob[0] * 100);
- unsigned int edges[_maxEdges][2] = {
+ std::vector<edge_index_s> defaultEdges {
{2, 3}, {4, 5}, {6, 7}, {8, 9},
{2, 4}, {3, 5}, {6, 8}, {7, 9},
{2, 6}, {3, 7}, {4, 8}, {5, 9}
};
- for (auto idx = 0; idx < _maxEdges; ++idx) {
- _result->edge_indexes[idx].start = edges[idx][0];
- _result->edge_indexes[idx].end = edges[idx][1];
- }
+ _result.edge_index_vec = defaultEdges;
+ _result.number_of_edges = defaultEdges.size();
- return _result.get();
+ return _result;
}
}
-}
\ No newline at end of file
+}