Address of hongsoft official website
Register the account on the official website, apply for the activation code of face recognition, select the SDK version and the operating system (windows/linux/android/ios), we select windows for the test, choose the application type as 1:N, and the functional modules include face detection, face tracking and face recognition. After application, the app ID and SDK key will be obtained, which will be used in the code.
Hong soft SDK face detection purpose
It is mainly compared with face + + face detection to see if we can select hongsoft to detect before face + + face detection.
c + + partial function realization
Select Qtcreator 4.2.1 to create a new c + + library.
Set QT. Pro file
#Don't load Qt library QT -= core gui #Build library name TARGET = detect_lib #Define build lib TEMPLATE = lib DEFINES += DETECT_LIB_LIBRARY SOURCES += detect_lib.cpp #Load siphon sdk header file HEADERS += detect_lib.h \ inc/amcomdef.h \ inc/ammem.h \ inc/arcsoft_fsdk_face_detection.h \ inc/asvloffscreen.h \ inc/merror.h unix { target.path = /usr/lib INSTALLS += target } unix|win32: LIBS += -L$$PWD/lib/ -llibarcsoft_fsdk_face_detection INCLUDEPATH += $$PWD/. DEPENDPATH += $$PWD/.
The above is the. pro file, mainly some configuration information, such as generating the library name to load the hongsoft SDK and header file
The following is the interface file of detect lib. H mainly used by nodejs.
#ifndef DETECT_LIB_H #define DETECT_LIB_H # ifdef __cplusplus # define EXTERN_NAME extern "C" # else # define EXTERN_NAME extern # endif #if defined(WIN32) # define Q_DECL_EXPORT __declspec(dllexport) # define Q_DECL_IMPORT __declspec(dllexport) #if defined(DETECT_LIB_LIBRARY) # define DETECT_LIBSHARED_EXPORT EXTERN_NAME Q_DECL_EXPORT # else # define DETECT_LIBSHARED_EXPORT EXTERN_NAME Q_DECL_IMPORT #endif #else # define DETECT_LIBSHARED_EXPORT EXTERN_NAME #endif DETECT_LIBSHARED_EXPORT int add(int a,int b); DETECT_LIBSHARED_EXPORT int detect(unsigned char * data,int width,int height); #endif // DETECT_LIB_H
Interface add function is mainly used for testing
int detect(unsigned char * data,int width,int height);
Face detection function, data: rgb pixel value, width: picture width, height: picture height
detect_lib.cpp
#include <nan.h> #include "detect_lib.h" using namespace Nan ; using namespace v8; class DetectWorker : public AsyncWorker { public: DetectWorker(Callback *callback, unsigned char* buffer,int width,int height) : AsyncWorker(callback), p_buffer(buffer), m_width(width),m_height(height) {m_num = 0;} ~DetectWorker() {} //This function runs on the worker thread, not the v8 thread, so it cannot access the data of v8 void Execute () { //m_num = add(12,3); m_num = detect(p_buffer,m_width,m_height); // m_num = 5; } //This is the callback function of libuv, where you can use the data of v8 void HandleOKCallback () { Local<Object> bmpData = NewBuffer(m_num).ToLocalChecked(); Local<Value> argv[] = { Nan::Null() ,Uint32::New(v8::Isolate::GetCurrent(),m_num) }; callback->Call(2, argv); }; private: unsigned char * p_buffer; int m_width; int m_height; int m_num; }; NAN_METHOD(detect){ unsigned char * buffer = (unsigned char*) node::Buffer::Data(info[0]->ToObject()); int width = info[1]->Uint32Value(); int height = info[2]->Uint32Value(); Callback *callback = new Callback(info[3].As<Function>()); AsyncQueueWorker(new DetectWorker(callback, buffer,width ,height)); } NAN_MODULE_INIT(Init) { Nan::Set(target,New<String>("detect").ToLocalChecked(), GetFunction(New<FunctionTemplate>(detect)).ToLocalChecked()); } NODE_MODULE(detect, Init)
NAN_METHOD(detect) means to define the interface detect. js can call it directly,
Here, the buffer in node is directly passed to c + + in byte mode. It is also an important way for nodejs to interact with c + +.
Copy the compiled dll, hongsoft sdk dll and detect lib. H to the current directory, and then generate. Node through node gyp configure and node gyp build
Now that the. node library is compiled, you can use require to directly drink the. node, such as: var detect = require('. / build/Release/detect.node');