added search api
git-svn-id: http://192.168.1.226/svn/proxy@672 454eff88-639b-444f-9e54-f578c98de674
| | |
| | | FDP_FaceDetectResult result(0, 0, int(c * 1000)); |
| | | return result; |
| | | } |
| | | |
| | | void STFaceCache::search(const STFaceImage& img, fdr_vec_t& topResult) |
| | | { |
| | | stface_ctx_map_t& dbContext(*(stface_ctx_map_t*)_dbContext); |
| | | STFaceCacheContext& cacheContext(*(STFaceCacheContext*)_cacheContext); |
| | | |
| | | /* |
| | | for(stface_ctx_map_t::iterator iterCtx = dbContext.begin(); iterCtx != dbContext.end(); ++iterCtx) |
| | | { |
| | | STFaceDBContext& ctx(iterCtx->second); |
| | | if (!ctx.dbLoadOK) |
| | | { |
| | | LOG_WARN << "dbLoadOK return false" << LOG_ENDL; |
| | | continue; |
| | | } |
| | | |
| | | top_idx_score_vect_t result; |
| | | if (!stface_search_db(ctx.handles, img, result)) |
| | | { |
| | | LOG_WARN << "stface_search_db return false" << LOG_ENDL; |
| | | continue; |
| | | } |
| | | |
| | | if (result.empty()) |
| | | { |
| | | LOG_INFO << "stface_search_db return empty" << LOG_ENDL; |
| | | continue; |
| | | } |
| | | |
| | | for(top_idx_score_vect_t::iterator it = result.begin(); it != result.end(); ++it) |
| | | { |
| | | if(topResult.empty()) |
| | | topResult.push_back(FDP_FaceDetectResult(ctx.dbid, it->idx, it->score * 1000)); |
| | | |
| | | int16_t new_confidence = it->score * 1000; |
| | | else if(new_confidence > topResult.rbegin()->confidence) |
| | | { |
| | | while(topResult.size() > 4) |
| | | topResult.pop_back(); |
| | | for(fdr_vec_t::reverse_iterator rtTR = topResult.rbegin() + 1; rtTR != topResult.rend(); ++rtTR) |
| | | { |
| | | if(new_confidence < rtTR->confidence) |
| | | topResult.insert(rtTR, FDP_FaceDetectResult(ctx.dbid, it->idx, new_confidence)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //LOGP(INFO, "stface_search_db return dbid=%d, idx=%d, score=%f", img.db_id, result[0].idx, result[0].score); |
| | | } |
| | | */ |
| | | |
| | | topResult.push_back(FDP_FaceDetectResult(1, 2, 3)); |
| | | topResult.push_back(FDP_FaceDetectResult(-1, 2, 4)); |
| | | topResult.push_back(FDP_FaceDetectResult(1, 6, 5)); |
| | | return FDP_FaceDetectResult(img.db_id, result[0].idx, result[0].score * 1000); |
| | | } |
| | |
| | | void close_dbs(); |
| | | FDP_FaceDetectResult detect(const STFaceImage& img); |
| | | FDP_FaceDetectResult add(const STFaceImage& img); |
| | | fdr_vec_t search(const STFaceImage& img); |
| | | void search(const STFaceImage& img, fdr_vec_t& topResult); |
| | | FDP_FaceDetectResult compare(const STFaceImage& img1, const STFaceImage& img2); |
| | | |
| | | //#todo need a delete img, if business not linked faceid and its personid |
| | |
| | | FDC_SENSETIMEFACEDETECT_RESULT_JSON,
|
| | | FDC_SENSETIMEFACEDETECT_SAVE,
|
| | | FDC_SENSETIMEFACEDETECT_COMPARE,
|
| | | FDC_SENSETIMEFACEDETECT_SEARCH,
|
| | | FDC__LAST,
|
| | | };
|
| | | };
|
| | |
| | | return send_SensetimeFaceDetectResultJson(client, result, 0);
|
| | | }
|
| | |
|
| | | bool ev_proc_SensetimeFaceDetectSearch(EVClientStub& client)
|
| | | {
|
| | | EVPHeader* evpHeader = (EVPHeader*)client.recvBuff;
|
| | | FDP_Image* fdpImage = (FDP_Image*)(client.recvBuff + sizeof(EVPHeader));
|
| | | fdpImage->ntoh();
|
| | | |
| | | STFaceImage stfaceImg;
|
| | | stfaceImg.db_id = fdpImage->db_id;
|
| | | stfaceImg.mb_type = fdpImage->mb_type;
|
| | | stfaceImg.width = fdpImage->width;
|
| | | stfaceImg.height = fdpImage->height;
|
| | | stfaceImg.size = evpHeader->size - sizeof(EVPHeader) - sizeof(FDP_Image);
|
| | | stfaceImg.buff = fdpImage->buff;
|
| | | |
| | | LOGP(DEBUG, "stfaceImg db_id=%d, mb_type=%d, width=%d, height=%d, size=%d", |
| | | (int)stfaceImg.db_id, (int)stfaceImg.mb_type, (int)stfaceImg.width, (int)stfaceImg.height, (int)stfaceImg.size);
|
| | | |
| | | |
| | | char imgfn[100 * 1024];
|
| | | static int i = 0;
|
| | | sprintf(imgfn, "IMG_%d_%d_w%d_h%d.rgb565", stfaceImg.db_id, ++i, stfaceImg.width, stfaceImg.height);
|
| | | FILE * pFile = fopen(imgfn, "wb");
|
| | | fwrite(stfaceImg.buff, sizeof(char), stfaceImg.size, pFile);
|
| | | fclose(pFile);
|
| | | pFile = nullptr;
|
| | | |
| | | fdr_vec_t result;
|
| | | g_STFaceCache.search(stfaceImg, result);
|
| | | |
| | | //int ret = (fdrResult.db_id == 0 ? -1 : 0);
|
| | | return send_SensetimeFaceDetectResultJson(client, result, 0);
|
| | | }
|
| | |
|
| | | bool ev_dispatcher_proto_pb(EVClientStub& client)
|
| | | {
|
| | | LOG_DEBUG << "ev_dispatcher_proto_pb" << LOG_ENDL;
|
| | |
| | | case FaceDaemonCommand::FDC_SENSETIMEFACEDETECT_COMPARE:
|
| | | return ev_proc_SensetimeFaceDetectCompare(client);
|
| | | break;
|
| | | case FaceDaemonCommand::FDC_SENSETIMEFACEDETECT_SEARCH:
|
| | | return ev_proc_SensetimeFaceDetectSearch(client);
|
| | | break;
|
| | | default:
|
| | | LOG_WARN << "Unknown command" << LOG_ENDL;
|
| | | ev_send_status_packet(client, EVPStatus::EVPS_COMMAND_ERROR);
|
| | |
| | | OPENCV_LIB=`PKG_CONFIG_PATH=$OPENCV_LIB/pkgconfig pkg-config --libs-only-l opencv` |
| | | OPENCV_LIB="-L$OPENCV_BASE/lib $OPENCV_LIB" |
| | | |
| | | CPPFLAGS+="-g -c -std=c++11 -pthread -DSERVER_PORT=15436 -DSTFACESDK_BASE=\"$STFACESDK_BASE\" -I$PIPELINE_BASE $PROTOBUF_INC $STFACESDK_INC $OPENCV_INC $LIBYUV_INC " |
| | | CPPFLAGS+="-g -c -std=c++11 -pthread -DSERVER_PORT=15432 -DSTFACESDK_BASE=\"$STFACESDK_BASE\" -I$PIPELINE_BASE $PROTOBUF_INC $STFACESDK_INC $OPENCV_INC $LIBYUV_INC " |
| | | LDFLAGS+="-pthread -levent $PROTOBUF_LIB $STFACESDK_LIB $OPENCV_LIB $LIBYUV_LIB " |
| | | |
| | | rm *.o |
New file |
| | |
| | | /************************************
|
| | | * For msmr |
| | | * server.c
|
| | | * tesing the speed of bufferevent_write
|
| | | * 2015-02-03
|
| | | * author@tom
|
| | | ************************************/
|
| | | #include <stdio.h>
|
| | | #include <stdlib.h>
|
| | | #include <string.h>
|
| | | #include <event2/event.h>
|
| | | #include <event2/bufferevent.h>
|
| | | #include <event2/buffer.h>
|
| | | #include <netinet/tcp.h>
|
| | | #include <arpa/inet.h>
|
| | |
|
| | | #include <unistd.h>
|
| | |
|
| | | #include "ev_proto.h"
|
| | | #include "face_daemon_proto.h"
|
| | |
|
| | | #include <iostream>
|
| | | #include <logger.h>
|
| | | #include <MaterialBuffer.h>
|
| | |
|
| | | Logger g_logger(std::cout);
|
| | |
|
| | | /*
|
| | | void make_msg(char* mesg, int& length)
|
| | | {
|
| | | EVPHeader* evpHeader = new (mesg) EVPHeader;
|
| | | evpHeader->proto = EVPProto::EVPP_PROTOBUF;
|
| | | evpHeader->cmd = FaceDaemonCommand::FDC_SENSETIMEFACEDETECT_PB;
|
| | | evpHeader->size = length;
|
| | | |
| | | FILE* pFile = fopen("facelist-3.pb", "rb");
|
| | | size_t fsize = fread(mesg + sizeof(EVPHeader), 1, length - sizeof(EVPHeader), pFile);
|
| | | fclose(pFile);
|
| | | }
|
| | | */
|
| | |
|
| | | void make_msg(char* mesg, int& length)
|
| | | {
|
| | | EVPHeader* evpHeader = new (mesg) EVPHeader;
|
| | | evpHeader->proto = EVPProto::EVPP_RAW_BIN; // 1
|
| | | evpHeader->cmd = FaceDaemonCommand::FDC_SENSETIMEFACEDETECT_SEARCH; // 133
|
| | | evpHeader->size = sizeof(EVPHeader);
|
| | |
|
| | | FDP_Image* fdpImage1 = nullptr;
|
| | | {
|
| | | fdpImage1 = new (mesg + evpHeader->size) FDP_Image;
|
| | |
|
| | | fdpImage1->db_id = 0; // -1
|
| | | fdpImage1->mb_type = MB_Frame::MBFT_JPEG; // 7
|
| | | fdpImage1->width = 291;
|
| | | fdpImage1->height = 194;
|
| | | |
| | | FILE* pFile = fopen("compare1.jpg", "rb");
|
| | | fdpImage1->size = fread(fdpImage1->buff, 1, length, pFile);
|
| | | fclose(pFile);
|
| | | pFile = nullptr;
|
| | |
|
| | | evpHeader->size += sizeof(FDP_Image) + fdpImage1->size;
|
| | | fdpImage1->hton();
|
| | | }
|
| | | |
| | | length = evpHeader->size;
|
| | | evpHeader->hton();
|
| | | }
|
| | |
|
| | | int main()
|
| | | {
|
| | | // build the message to be sent
|
| | | int length = 1024 * 1024; // the size of message
|
| | | char* mesg = (char*)malloc((length+1)*sizeof(char)); // Look out the end mark '/0' of a C string
|
| | | if (mesg == NULL)
|
| | | exit(1);
|
| | | int i;
|
| | | //for (i=0; i<length; i++) |
| | | // strcat(mesg, "a");
|
| | |
|
| | | make_msg(mesg, length);
|
| | |
|
| | | printf("%s\n", mesg);
|
| | | printf("%d\n", length);
|
| | |
|
| | | // build socket
|
| | | int port = 15434;
|
| | |
|
| | | struct sockaddr_in server_addr;
|
| | | memset(&server_addr, 0, sizeof(server_addr));
|
| | | server_addr.sin_family = AF_INET;
|
| | | server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
|
| | | server_addr.sin_port = htons(port);
|
| | |
|
| | | // build event base
|
| | | struct event_base* base = event_base_new();
|
| | |
|
| | | // set TCP_NODELAY to let data arrive at the server side quickly
|
| | | evutil_socket_t fd;
|
| | | fd = socket(AF_INET, SOCK_STREAM, 0);
|
| | | struct bufferevent* conn = bufferevent_socket_new(base,fd,BEV_OPT_CLOSE_ON_FREE);
|
| | | int enable = 1;
|
| | | if(setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (void*)&enable, sizeof(enable)) < 0)
|
| | | printf("ERROR: TCP_NODELAY SETTING ERROR!\n");
|
| | | //bufferevent_setcb(conn, NULL, NULL, NULL, NULL); // For client, we don't need callback function
|
| | | bufferevent_enable(conn, EV_WRITE);
|
| | | if(bufferevent_socket_connect(conn,(struct sockaddr*)&server_addr,sizeof(server_addr)) == 0)
|
| | | printf("connect success\n");
|
| | |
|
| | | // start to send data
|
| | | bufferevent_write(conn,mesg,length);
|
| | | // check the output evbuffer
|
| | | struct evbuffer* output = bufferevent_get_output(conn);
|
| | |
|
| | | event_base_dispatch(base);
|
| | | |
| | | char readbuf[10];
|
| | | int readbufsize = read(fd, readbuf, sizeof(readbuf));
|
| | | while(readbufsize>0)
|
| | | {
|
| | | readbuf[readbufsize] = '\0';
|
| | | printf("%s", readbuf);
|
| | | readbufsize = read(fd, readbuf, sizeof(readbuf));
|
| | | }
|
| | | printf("\n");
|
| | |
|
| | | free(mesg);
|
| | | mesg = NULL;
|
| | |
|
| | | bufferevent_free(conn);
|
| | | event_base_free(base);
|
| | |
|
| | | printf("Client program is over\n");
|
| | |
|
| | | return 0;
|
| | | } |