#include "sdk.h" #include #include #include #include #include #ifdef __cplusplus // extern "C" { #endif #include "std_target.h" // sdk interface func name // sdk-interface-name const static char sin_create[] = "create"; const static char sin_get_result_face[] = "get_result_face"; const static char sin_set_data[] = "set_data"; const static char sin_op_channel[] = "op_channel"; const static char sin_set_cb[] = "set_cb"; const static char sin_release[] = "release"; const static char sin_get_result[] = "get_result"; const static char sin_release_result[] = "release_result"; #define check(lib, fn, log, lib_name, fn_name, ret) do{ \ if (!fn){ \ dlclose(lib); \ lib=NULL; \ printf("dlsym func \"%s\" from file \"%s\" failed", fn_name, lib_name); \ return ret; \ } \ }while(0) namespace container { sdk::sdk(const char *id) :libsdk_(nullptr) ,sdk_handle_(nullptr) ,fn_create(nullptr) ,fn_get_result_face(nullptr) ,fn_set_data(nullptr) ,fn_op_channel(nullptr) ,fn_set_cb(nullptr) ,fn_release(nullptr) ,fn_get_result(nullptr) ,fn_release_result(nullptr) ,id_or_name_(id) {} sdk::~sdk() { release(); } int sdk::release(){ if (sdk_handle_ && fn_release){ fn_release(sdk_handle_); } if (libsdk_){ dlclose(libsdk_); libsdk_ = NULL; } return 0; } int sdk::fndd(void *args, const int sender_chan, const char *recver, const char *data, const int len) { printf("call back func \n"); fn_set_data(sdk_handle_, data, strlen(data), 1); return 0; } int sdk::init(const char *so, const char *conf){ if (libsdk_) return 0; libsdk_ = dlopen(so, RTLD_LAZY); if (!libsdk_) { printf("sdk dlopen %s conf %s error %s\n", so, conf, dlerror()); return -1; } // MUST EXIST FUNCTIONS fn_create = (fn_sdk_create)dlsym(libsdk_, sin_create); check(libsdk_, fn_create, fn_log_, so, sin_create, -1); fn_get_result_face = (fn_sdk_get_result_face)dlsym(libsdk_, sin_get_result_face); check(libsdk_, fn_get_result_face, fn_log_, so, sin_get_result_face, -1); fn_set_data = (fn_sdk_set_data)dlsym(libsdk_, sin_set_data); check(libsdk_, fn_set_data, fn_log_, so, sin_set_data, -1); fn_op_channel = (fn_sdk_op_channel)dlsym(libsdk_, sin_op_channel); check(libsdk_, fn_op_channel, fn_log_, so, sin_op_channel, -1); fn_set_cb = (fn_sdk_set_cb)dlsym(libsdk_, sin_set_cb); check(libsdk_, fn_set_cb, fn_log_, so, sin_set_cb, -1); fn_release = (fn_sdk_release)dlsym(libsdk_, sin_release); check(libsdk_, fn_release, fn_log_, so, sin_release, -1); fn_get_result = (fn_sdk_get_result)dlsym(libsdk_, sin_get_result); check(libsdk_, fn_get_result, fn_log_, so, sin_get_result, -1); fn_release_result = (fn_sdk_release_result)dlsym(libsdk_, sin_release_result); check(libsdk_, fn_release_result, fn_log_, so, sin_release_result, -1); int max_chan = 7; if ((sdk_handle_ = fn_create(conf, &max_chan)) == NULL){ printf("sdk create sdk handle failed"); return -1; } const char* data = "[[{\"cameraId\":\"b0b766c2-e29f-432f-aabb-0bedd36c604b\",\"polygonId\":\"7196c66f-5b82-449c-a08c-9f53a5d48ed4\",\"polygon\":[{\"x\":397,\"y\":348},{\"x\":72,\"y\":537},{\"x\":953,\"y\":539}],\"coordTrans\":[{\"x0\":261,\"y0\":0,\"x1\":0,\"y1\":0},{\"x0\":427,\"y0\":474,\"x1\":33,\"y1\":234}]},{\"cameraId\":\"18e2c6f1-fd3e-4bc6-b878-5a38228cebe8\",\"polygonId\":\"20b88549-6c41-4b30-844b-088215095995\",\"polygon\":[{\"x\":197,\"y\":179},{\"x\":252,\"y\":532},{\"x\":675,\"y\":535},{\"x\":470,\"y\":154},{\"x\":470,\"y\":154},{\"x\":378,\"y\":185}],\"coordTrans\":[{\"x0\":304,\"y0\":0,\"x1\":0,\"y1\":0},{\"x0\":415,\"y0\":372,\"x1\":1235,\"y1\":432}]}]]"; fn_set_data(sdk_handle_, data, strlen(data), 0); const char* map_chan = "{\"name\":\"b0b766c2-e29f-432f-aabb-0bedd36c604b\",\"id\":0}"; fn_op_channel(sdk_handle_, map_chan, strlen(map_chan), 1); map_chan = "{\"name\":\"18e2c6f1-fd3e-4bc6-b878-5a38228cebe8\",\"id\":1}"; fn_op_channel(sdk_handle_, map_chan, strlen(map_chan), 1); char* aa= "ddf"; // fn_set_cb(sdk_handle_, sdk::fndd, aa); if (max_chan <= 0) max_chan = 16; return 0; } int sdk::run(void *pic_data, int w, int h, int chn) { TImage img; img.width = w; img.height = h; img.channel = chn; img.data = (unsigned char *)pic_data; const int face_info_size = 0; char* face_info; // void * sr = fn_get_result(sdk_handle_, &img, 0); void * sr = fn_get_result_face(sdk_handle_, &img, 0, face_info, face_info_size); TResult * t_result = (TResult*) sr; printf("t_result->count==%d\n", t_result->count); for (int i = 0; i count ; ++i) { printf("=======id:%d confidence:%d left:%d top:%d \n",t_result->targets[i].id,t_result->targets[i].confidence , t_result->targets[i].rect.left, t_result->targets[i].rect.top ); } fn_release_result(sr); //free(img); return 1; } } // namespace container #ifdef __cplusplus // } #endif