#include "mv_selfie_segmentation_internal.h"
#include "selfie_segmentation_adapter.h"
#include "machine_learning_exception.h"
+#include "MachineLearningNative.h"
#include "image_segmentation_type.h"
#include "context.h"
#include <mutex>
#include <iostream>
+#define TASK_NAME "selfie_segmentation"
+
using namespace std;
using namespace mediavision::inference;
using namespace mediavision::common;
MEDIA_VISION_FUNCTION_ENTER();
- Context *context = nullptr;
- ITask *task = nullptr;
+ mv_selfie_segmentation_h ctx = nullptr;
try {
- context = new Context();
- task = new ImageSegmentationAdapter();
- context->__tasks.insert(make_pair("selfie_segmentation", task));
- *handle = static_cast<mv_selfie_segmentation_h>(context);
+ ctx = machine_learning_native_create();
+ machine_learning_native_add(ctx, TASK_NAME, new ImageSegmentationAdapter());
} catch (const BaseException &e) {
- delete task;
- delete context;
+ LOGE("%s", e.what());
return e.getError();
}
+ *handle = ctx;
MEDIA_VISION_FUNCTION_LEAVE();
return MEDIA_VISION_ERROR_NONE;
MEDIA_VISION_FUNCTION_ENTER();
- auto context = static_cast<Context *>(handle);
-
- for (auto &m : context->__tasks)
- delete m.second;
-
- delete context;
+ machine_learning_native_destory(handle);
MEDIA_VISION_FUNCTION_LEAVE();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("selfie_segmentation");
-
- task->setModelInfo(model_file, meta_file, label_file, model_name);
+ machine_learning_native_set_model(handle, TASK_NAME, model_file, meta_file, label_file);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("selfie_segmentation");
-
- task->setEngineInfo(backend_type, device_type);
+ machine_learning_native_set_engine(handle, TASK_NAME, backend_type, device_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("selfie_segmentation");
-
- *engine_count = task->getNumberOfEngines();
- // TODO.
+ machine_learning_native_get_engine_count(handle, TASK_NAME, engine_count);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("selfie_segmentation");
-
- *engine_type = (char *) task->getEngineType(engine_index).c_str();
- // TODO.
+ machine_learning_native_get_engine_type(handle, TASK_NAME, engine_index, engine_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("selfie_segmentation");
-
- *device_count = task->getNumberOfDevices(engine_type);
- // TODO.
+ machine_learning_native_get_device_count(handle, TASK_NAME, engine_type, device_count);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("selfie_segmentation");
-
- *device_type = (char *) task->getDeviceType(engine_type, device_index).c_str();
- // TODO.
+ machine_learning_native_get_device_type(handle, TASK_NAME, engine_type, device_index, device_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("selfie_segmentation");
-
- task->configure();
+ machine_learning_native_configure(handle, TASK_NAME);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("selfie_segmentation");
-
- task->prepare();
+ machine_learning_native_prepare(handle, TASK_NAME);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("selfie_segmentation");
-
- ImageSegmentationInput input = { .inference_src = source };
+ ImageSegmentationInput input(source);
- task->perform(input);
+ machine_learning_native_inference(handle, TASK_NAME, input);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("selfie_segmentation");
-
- ImageSegmentationInput input = { source };
+ ImageSegmentationInput input(source);
- task->performAsync(input);
+ machine_learning_native_inference_async(handle, TASK_NAME, input);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("selfie_segmentation");
+ auto &result = static_cast<ImageSegmentationResult &>(machine_learning_native_get_result(handle, TASK_NAME));
- auto &result = static_cast<ImageSegmentationResult &>(task->getOutput());
*width = result.width;
*height = result.height;
*pixel_size = result.pixel_size;
#include "mv_object_detection_3d_internal.h"
#include "object_detection_3d_adapter.h"
#include "machine_learning_exception.h"
+#include "MachineLearningNative.h"
#include "object_detection_3d_type.h"
#include "context.h"
#include <algorithm>
#include <mutex>
+#define TASK_NAME "object_detection_3d"
+
using namespace std;
using namespace mediavision::inference;
using namespace mediavision::common;
MEDIA_VISION_FUNCTION_ENTER();
- Context *context = nullptr;
- ITask *task = nullptr;
+ mv_object_detection_3d_h ctx = nullptr;
try {
- context = new Context();
- task = new ObjectDetection3dAdapter();
- context->__tasks.insert(make_pair("object_detection_3d", task));
- *handle = static_cast<mv_object_detection_3d_h>(context);
+ ctx = machine_learning_native_create();
+ machine_learning_native_add(ctx, TASK_NAME, new ObjectDetection3dAdapter());
} catch (const BaseException &e) {
- delete task;
- delete context;
+ LOGE("%s", e.what());
return e.getError();
}
+ *handle = ctx;
MEDIA_VISION_FUNCTION_LEAVE();
return MEDIA_VISION_ERROR_NONE;
MEDIA_VISION_FUNCTION_ENTER();
- auto context = static_cast<Context *>(handle);
-
- for (auto &m : context->__tasks)
- delete m.second;
-
- delete context;
+ machine_learning_native_destory(handle);
MEDIA_VISION_FUNCTION_LEAVE();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
-
- task->setModelInfo(model_file, meta_file, label_file, model_name);
+ machine_learning_native_set_model(handle, TASK_NAME, model_file, meta_file, label_file, model_name);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
-
- task->setEngineInfo(backend_type, device_type);
+ machine_learning_native_set_engine(handle, TASK_NAME, backend_type, device_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
-
- *engine_count = task->getNumberOfEngines();
- // TODO.
+ machine_learning_native_get_engine_count(handle, TASK_NAME, engine_count);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
-
- *engine_type = (char *) task->getEngineType(engine_index).c_str();
- // TODO.
+ machine_learning_native_get_engine_type(handle, TASK_NAME, engine_index, engine_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
-
- *device_count = task->getNumberOfDevices(engine_type);
- // TODO.
+ machine_learning_native_get_device_count(handle, TASK_NAME, engine_type, device_count);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
-
- *device_type = (char *) task->getDeviceType(engine_type, device_index).c_str();
- // TODO.
+ machine_learning_native_get_device_type(handle, TASK_NAME, engine_type, device_index, device_type);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
-
- task->configure();
+ machine_learning_native_configure(handle, TASK_NAME);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
-
- task->prepare();
+ machine_learning_native_prepare(handle, TASK_NAME);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
+ ObjectDetection3dInput input(source);
- ObjectDetection3dInput input = { source };
-
- task->perform(input);
+ machine_learning_native_inference(handle, TASK_NAME, input);
} catch (const BaseException &e) {
LOGE("%s", e.what());
return e.getError();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
-
- auto &result = static_cast<ObjectDetection3dResult &>(task->getOutput());
+ auto &result = static_cast<ObjectDetection3dResult &>(machine_learning_native_get_result(handle, TASK_NAME));
*out_probability = result.probability;
} catch (const BaseException &e) {
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
-
- auto &result = static_cast<ObjectDetection3dResult &>(task->getOutput());
+ auto &result = static_cast<ObjectDetection3dResult &>(machine_learning_native_get_result(handle, TASK_NAME));
*out_num_of_points = result.number_of_points;
} catch (const BaseException &e) {
MEDIA_VISION_FUNCTION_ENTER();
try {
- Context *context = static_cast<Context *>(handle);
- auto task = context->__tasks.at("object_detection_3d");
-
- auto &result = static_cast<ObjectDetection3dResult &>(task->getOutput());
+ auto &result = static_cast<ObjectDetection3dResult &>(machine_learning_native_get_result(handle, TASK_NAME));
*out_x = result.x_vec.data();
*out_y = result.y_vec.data();