Files
ai-box/cxx/node.cc
2025-03-06 14:38:32 +08:00

65 lines
1.4 KiB
C++

#include <unistd.h>
#include <napi.h>
#include "cv/node.h"
#ifdef USE_ORT
#include "ort/node.h"
#endif
using namespace Napi;
class TestWork : public AsyncWorker
{
public:
TestWork(const Napi::Function &callback, int value) : Napi::AsyncWorker(callback), val_(value) {}
~TestWork() {}
void Execute()
{
printf("the worker-thread doing! %d \n", val_);
sleep(3);
printf("the worker-thread done! %d \n", val_);
}
void OnOK()
{
Callback().Call({Env().Undefined(), Number::New(Env(), 0)});
}
private:
int val_;
};
Value test(const CallbackInfo &info)
{
// ai::ORTSession(nullptr, 0);
// Function callback = info[1].As<Function>();
// TestWork *work = new TestWork(callback, info[0].As<Number>().Int32Value());
// work->Queue();
return info.Env().Undefined();
}
Object Init(Env env, Object exports)
{
//OpenCV
NODE_INIT_OBJECT(cv, InstallOpenCVAPI);
//OnnxRuntime
#ifdef USE_ORT
NODE_INIT_OBJECT(ort, InstallOrtAPI);
#endif
Napi::Number::New(env, 0);
#define ADD_FUNCTION(name) exports.Set(Napi::String::New(env, #name), Napi::Function::New(env, name))
// ADD_FUNCTION(facedetPredict);
// ADD_FUNCTION(facedetRelease);
// ADD_FUNCTION(faceRecognitionCreate);
// ADD_FUNCTION(faceRecognitionPredict);
// ADD_FUNCTION(faceRecognitionRelease);
// ADD_FUNCTION(getDistance);
#undef ADD_FUNCTION
return exports;
}
NODE_API_MODULE(addon, Init)