修复Windows编译问题
This commit is contained in:
106
cxx/node.cc
106
cxx/node.cc
@ -1,65 +1,65 @@
|
||||
#include <unistd.h>
|
||||
#include <napi.h>
|
||||
#include "cv/node.h"
|
||||
#ifdef USE_ORT
|
||||
#include "ort/node.h"
|
||||
#endif
|
||||
// #include <unistd.h>
|
||||
// #include <napi.h>
|
||||
// #include "cv/node.h"
|
||||
// #ifdef USE_ORT
|
||||
// #include "ort/node.h"
|
||||
// #endif
|
||||
|
||||
using namespace Napi;
|
||||
// using namespace Napi;
|
||||
|
||||
class TestWork : public AsyncWorker
|
||||
{
|
||||
public:
|
||||
TestWork(const Napi::Function &callback, int value) : Napi::AsyncWorker(callback), val_(value) {}
|
||||
~TestWork() {}
|
||||
// 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 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)});
|
||||
}
|
||||
// void OnOK()
|
||||
// {
|
||||
// Callback().Call({Env().Undefined(), Number::New(Env(), 0)});
|
||||
// }
|
||||
|
||||
private:
|
||||
int val_;
|
||||
};
|
||||
// private:
|
||||
// int val_;
|
||||
// };
|
||||
|
||||
Value test(const CallbackInfo &info)
|
||||
{
|
||||
// ai::ORTSession(nullptr, 0);
|
||||
// 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();
|
||||
}
|
||||
// // 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
|
||||
// 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);
|
||||
// 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);
|
||||
// #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(faceRecognitionCreate);
|
||||
// // ADD_FUNCTION(faceRecognitionPredict);
|
||||
// // ADD_FUNCTION(faceRecognitionRelease);
|
||||
|
||||
// ADD_FUNCTION(getDistance);
|
||||
#undef ADD_FUNCTION
|
||||
return exports;
|
||||
}
|
||||
NODE_API_MODULE(addon, Init)
|
||||
// // ADD_FUNCTION(getDistance);
|
||||
// #undef ADD_FUNCTION
|
||||
// return exports;
|
||||
// }
|
||||
// NODE_API_MODULE(addon, Init)
|
@ -3,6 +3,12 @@
|
||||
#include <onnxruntime_cxx_api.h>
|
||||
#include "node.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
using namespace Napi;
|
||||
|
||||
#define SESSION_INSTANCE_METHOD(method) InstanceMethod<&OrtSession::method>(#method, static_cast<napi_property_attributes>(napi_writable | napi_configurable))
|
||||
@ -168,7 +174,23 @@ class OrtSession : public ObjectWrap<OrtSession> {
|
||||
: ObjectWrap(info)
|
||||
{
|
||||
try {
|
||||
if (info[0].IsString()) session_ = std::make_shared<Ort::Session>(env, info[0].As<String>().Utf8Value().c_str(), sessionOptions);
|
||||
if (info[0].IsString()) {
|
||||
#ifdef WIN32
|
||||
std::string str = info[0].As<String>().Utf8Value();
|
||||
auto len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), NULL, 0);
|
||||
wchar_t *buffer = new wchar_t[len + 1];
|
||||
MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.size(), buffer, len);
|
||||
buffer[len] = '\0';
|
||||
std::wstring filename(buffer);
|
||||
delete[] buffer;
|
||||
|
||||
// std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
// std::wstring filename = converter.from_bytes(info[0].As<String>().Utf8Value());
|
||||
session_ = std::make_shared<Ort::Session>(env, filename.c_str(), sessionOptions);
|
||||
#else
|
||||
session_ = std::make_shared<Ort::Session>(env, info[0].As<String>().Utf8Value().c_str(), sessionOptions);
|
||||
#endif
|
||||
}
|
||||
else if (info[0].IsTypedArray()) {
|
||||
size_t bufferBytes;
|
||||
auto buffer = dataFromTypedArray(info[0], bufferBytes);
|
||||
|
Reference in New Issue
Block a user