#include "mv_facial_landmark_internal.h"
#include "facial_landmark_adapter.h"
#include "machine_learning_exception.h"
+#include "MachineLearningNative.h"
#include "landmark_detection_type.h"
#include "context.h"
#include <unistd.h>
#include <string>
#include <algorithm>
-#include <mutex>
-#include <iostream>
+
+#define TASK_NAME "facial_landmark"
using namespace std;
using namespace mediavision::inference;
using namespace mediavision::machine_learning;
using namespace MediaVision::Common;
using namespace mediavision::machine_learning::exception;
-using LandmarkDetectionTask = ITask<InputBaseType, OutputBaseType>;
+using LandmarkDetectionTask = FacialLandmarkAdapter<InputBaseType, OutputBaseType>;
int mv_facial_landmark_create(mv_facial_landmark_h *handle)
{
MEDIA_VISION_FUNCTION_ENTER();
- Context *context = nullptr;
- LandmarkDetectionTask *task = nullptr;
-
try {
- context = new Context();
- task = new FacialLandmarkAdapter<InputBaseType, OutputBaseType>();
- context->__tasks.insert(make_pair("facial_landmark", task));
- *handle = static_cast<mv_facial_landmark_h>(context);
+ machine_learning_native_create<InputBaseType, OutputBaseType>(TASK_NAME, new LandmarkDetectionTask(), handle);
} catch (const BaseException &e) {
- delete task;
- delete context;
+ LOGE("%s", e.what());
return e.getError();
}
MEDIA_VISION_FUNCTION_ENTER();
- auto context = static_cast<Context *>(handle);
-
- for (auto &m : context->__tasks)
- delete static_cast<LandmarkDetectionTask *>(m.second);
-
- delete context;
+ machine_learning_native_destory(handle, TASK_NAME);
MEDIA_VISION_FUNCTION_LEAVE();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<LandmarkDetectionTask *>(context->__tasks.at("facial_landmark"));
-
- 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("facial_landmark"));
-
- 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("facial_landmark"));
-
- task->getNumberOfEngines(engine_count);
- // 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("facial_landmark"));
-
- task->getEngineType(engine_index, engine_type);
- // 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("facial_landmark"));
-
- task->getNumberOfDevices(engine_type, device_count);
- // 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("facial_landmark"));
-
- task->getDeviceType(engine_type, device_index, device_type);
- // 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("facial_landmark"));
-
- 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("facial_landmark"));
-
- 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("facial_landmark"));
-
LandmarkDetectionInput input(source);
- task->setInput(input);
- task->perform();
+ 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("facial_landmark"));
-
LandmarkDetectionInput 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("facial_landmark"));
-
- auto &result = static_cast<LandmarkDetectionResult &>(task->getOutput());
+ auto &result = static_cast<LandmarkDetectionResult &>(machine_learning_native_get_result(handle, TASK_NAME));
*number_of_landmarks = result.number_of_landmarks;
*pos_x = result.x_pos.data();
*pos_y = result.y_pos.data();
#include "mv_pose_landmark_internal.h"
#include "pose_landmark_adapter.h"
#include "machine_learning_exception.h"
+#include "MachineLearningNative.h"
#include "landmark_detection_type.h"
#include "context.h"
#include <unistd.h>
#include <string>
#include <algorithm>
-#include <mutex>
-#include <iostream>
+
+#define TASK_NAME "pose_landmark"
using namespace std;
using namespace mediavision::inference;
using namespace mediavision::machine_learning;
using namespace MediaVision::Common;
using namespace mediavision::machine_learning::exception;
-using LandmarkDetectionTask = ITask<InputBaseType, OutputBaseType>;
+using LandmarkDetectionTask = PoseLandmarkAdapter<InputBaseType, OutputBaseType>;
int mv_pose_landmark_create(mv_pose_landmark_h *handle)
{
MEDIA_VISION_FUNCTION_ENTER();
- Context *context = nullptr;
- LandmarkDetectionTask *task = nullptr;
-
try {
- context = new Context();
- task = new PoseLandmarkAdapter<InputBaseType, OutputBaseType>();
- context->__tasks.insert(make_pair("pose_landmark", task));
- *handle = static_cast<mv_pose_landmark_h>(context);
+ machine_learning_native_create<InputBaseType, OutputBaseType>(TASK_NAME, new LandmarkDetectionTask(), handle);
} catch (const BaseException &e) {
- delete task;
- delete context;
+ LOGE("%s", e.what());
return e.getError();
}
MEDIA_VISION_FUNCTION_ENTER();
- auto context = static_cast<Context *>(handle);
-
- for (auto &m : context->__tasks)
- delete static_cast<LandmarkDetectionTask *>(m.second);
-
- delete context;
+ machine_learning_native_destory(handle, TASK_NAME);
MEDIA_VISION_FUNCTION_LEAVE();
MEDIA_VISION_FUNCTION_ENTER();
try {
- auto context = static_cast<Context *>(handle);
- auto task = static_cast<LandmarkDetectionTask *>(context->__tasks.at("pose_landmark"));
-
- 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("pose_landmark"));
-
- 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("pose_landmark"));
-
- task->getNumberOfEngines(engine_count);
- // 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("pose_landmark"));
-
- task->getEngineType(engine_index, engine_type);
- // 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("pose_landmark"));
-
- task->getNumberOfDevices(engine_type, device_count);
- // 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("pose_landmark"));
-
- task->getDeviceType(engine_type, device_index, device_type);
- // 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("pose_landmark"));
-
- 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("pose_landmark"));
-
- 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("pose_landmark"));
-
LandmarkDetectionInput input(source);
- task->setInput(input);
- task->perform();
+ 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("pose_landmark"));
-
LandmarkDetectionInput 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 = static_cast<LandmarkDetectionTask *>(context->__tasks.at("pose_landmark"));
-
- auto &result = static_cast<LandmarkDetectionResult &>(task->getOutput());
+ auto &result = static_cast<LandmarkDetectionResult &>(machine_learning_native_get_result(handle, TASK_NAME));
*number_of_landmarks = result.number_of_landmarks;
*pos_x = result.x_pos.data();
*pos_y = result.y_pos.data();