namespace machine_learning
{
-Objectron::Objectron() : _result()
+Objectron::Objectron()
{
_inference = make_unique<Inference>();
+ _result = make_unique<object_detection_3d_result_s>();
}
Objectron::~Objectron()
void Objectron::parseMetaFile()
{
_config = make_unique<EngineConfig>(string(MV_CONFIG_PATH) +
- string(OBJECT_DETECTION_3D_META_FILE_NAME));
+ string(MV_OBJECT_DETECTION_3D_META_FILE_NAME));
int ret = _config->getIntegerAttribute(string(MV_OBJECT_DETECTION_3D_BACKEND_TYPE),
- &_backend_type);
+ &_backendType);
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to get backend engine type.");
ret = _config->getIntegerAttribute(string(MV_OBJECT_DETECTION_3D_TARGET_DEVICE_TYPE),
- &_target_device_type);
+ &_targetDeviceType);
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to get target device type.");
- ret = _config->getStringAttribute(MV_OBJECT_DETECTION_3D_MODEL_FILE_PATH, &_model_file_path);
+ 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 = _config->getStringAttribute(MV_OBJECT_DETECTION_3D_MODEL_META_FILE_PATH, &_model_meta_file_path);
+ ret = _config->getStringAttribute(MV_OBJECT_DETECTION_3D_MODEL_META_FILE_PATH, &_modelMetaFilePath);
if (ret != MEDIA_VISION_ERROR_NONE)
throw InvalidOperation("Fail to get model meta file path");
- if (_model_meta_file_path.empty())
+ if (_modelMetaFilePath.empty())
throw InvalidOperation("Model meta file doesn't exist.");
- if (!IsJsonFile(_model_meta_file_path))
+ if (!IsJsonFile(_modelMetaFilePath))
throw InvalidOperation("Model meta file should be json");
- ret = _inference->ParseMetadata(_model_meta_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()
float y_scale = static_cast<float>(_inference->getSourceHeight()) / static_cast<float>(_inference->getInputHeight());
for (unsigned int idx = 0; idx < output_size; idx += 2) {
- _result.x[result_idx] = static_cast<int>(keypoints[idx] * x_scale);
- _result.y[result_idx++] = static_cast<int>(keypoints[idx + 1] * y_scale);
+ _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.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->probability = static_cast<unsigned int>(prob[0] * 100);
- _result.number_of_edges = 12;
+ _result->number_of_edges = _maxEdges;
- unsigned int edges[12][2] = {
+ unsigned int edges[_maxEdges][2] = {
{2, 3}, {4, 5}, {6, 7}, {8, 9},
{2, 4}, {3, 5}, {6, 8}, {7, 9},
{2, 6}, {3, 7}, {4, 8}, {5, 9}
};
- ::copy(&edges[0][0], &edges[0][0] + 12 * 2, &_result.edge_indexes[0][0]);
+ for (auto idx = 0; idx < _maxEdges; ++idx) {
+ _result->edge_indexes[idx].start = edges[idx][0];
+ _result->edge_indexes[idx].end = edges[idx][1];
+ }
- return &_result;
+ return _result.get();
}
}