From 307706a63521650ca1cc7eebff0a931b432539c3 Mon Sep 17 00:00:00 2001
From: pans <pans@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期三, 11 一月 2017 19:09:50 +0800
Subject: [PATCH] faceAPI整合
---
RtspFace/main_face_daemon.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 92 insertions(+), 24 deletions(-)
diff --git a/RtspFace/main_face_daemon.cpp b/RtspFace/main_face_daemon.cpp
index 9ee5d4a..b614719 100644
--- a/RtspFace/main_face_daemon.cpp
+++ b/RtspFace/main_face_daemon.cpp
@@ -12,6 +12,7 @@
#include "PL_Payer.h"
#include "PL_Gainer.h"
#include "PL_SensetimeFaceTrack.h"
+#include "PL_SensetimeFaceDetect.h"
#include "PL_DlibFaceTrack.h"
#include "PipeLinePool.h"
@@ -20,21 +21,77 @@
#include "ev_proto.h"
#include "face_daemon_proto.h"
+#include "SensetimeFaceAPIWrapper/src/FaceDBPool.h"
+
#include "logger.h"
+
+template<typename TPoolPtr, typename TPoolElem>
+struct PoolElemLocker
+{
+ TPoolPtr pool;
+ TPoolElem elem;
+ PoolElemLocker(TPoolPtr _pool, TPoolElem _elem) : pool(_pool), elem(_elem)
+ {
+
+ }
+ ~PoolElemLocker()
+ {
+ pool->release(elem);
+ pool->notify_free();
+ }
+};
+
+template<typename TArrayPtr>
+struct ArrayDeleter
+{
+ TArrayPtr array;
+ ArrayDeleter(TArrayPtr _array) : array(_array)
+ {
+
+ }
+ ~ArrayDeleter()
+ {
+ delete[] array;
+ }
+};
PipeLinePool g_PipeLinePool;
+FaceDBPool g_faceAPIPool;//#todo config
+
evclient_proc_t evclient_proc;
-void send_SensetimeFaceDetectResult(PipeMaterial& lastPm)
+bool send_SensetimeFaceDetectResult(EVClientStub& client, PipeMaterial& lastPm)
{
- if (lastPm.type == PipeMaterial::PMT_PM_LIST)
+ //if (lastPm.type != PipeMaterial::PMT_PM_LIST)
+
+ //PipeMaterial& facePM = ((PipeMaterial*)(lastPm.buffer))[1];
+ //st_ff_vect_t& faceFeatures = *((st_ff_vect_t*)facePM.buffer);
+ //LOG_NOTICE << "faceFeatures " << faceFeatures.size();
+ //#todo send result packet
+
+ if (lastPm.buffer == nullptr || lastPm.type != PipeMaterial::PMT_BYTES || lastPm.buffSize != sizeof(SensetimeFaceDetectResult))
{
- PipeMaterial& facePM = ((PipeMaterial*)(lastPm.buffer))[1];
- st_ff_vect_t& faceFeatures = *((st_ff_vect_t*)facePM.buffer);
- LOG_NOTICE << "faceFeatures " << faceFeatures.size();
- //#todo send result packet
+ LOG_WARN << "pm not available";
+ ev_send_status_packet(client, EVPStatus::EVPS_INTERNAL_ERROR);
+ return false;
}
+
+ const SensetimeFaceDetectResult* result = (const SensetimeFaceDetectResult*)lastPm.buffer;
+
+ client.sendBuffSize = sizeof(EVPHeader)+sizeof(SensetimeFaceDetectResult);
+ client.sendBuff = new uint8_t[client.sendBuffSize];
+ client.deleteSendBuff = true;
+
+ EVPHeader* evpHeader = new (client.sendBuff) EVPHeader;
+ evpHeader->cmd = FaceDaemonCommand::FDC_SENSETIMEFACEDETECT_RESULT;
+ evpHeader->size = client.sendBuffSize;
+
+ SensetimeFaceDetectResult* evpSub = new (client.sendBuff + sizeof(EVPHeader)) SensetimeFaceDetectResult;
+ evpSub->school_id = result->school_id;
+ evpSub->st_id = result->st_id;
+
+ return true;
}
bool ev_proc_SensetimeFaceDetect(EVClientStub& client)
@@ -44,11 +101,18 @@
//return true;
FDP_Image* fdpImage = (FDP_Image*)(client.recvBuff + sizeof(EVPHeader));
+
+ faceAPI* _faceAPI = g_faceAPIPool.get_free(fdpImage->school_id);
+ if (_faceAPI == nullptr)
+ {
+ LOG_WARN << "can't get face db";
+ ev_send_status_packet(client, EVPStatus::EVPS_PARAMETER_ERROR);
+ return false;
+ }
- PipeLine* pipeLine = nullptr;
- if (g_PipeLinePool.wait_free())
- pipeLine = g_PipeLinePool.get_free();
-
+ PoolElemLocker<FaceDBPool*, int> _lock_faceAPI(&g_faceAPIPool, fdpImage->school_id);
+
+ PipeLine* pipeLine = g_PipeLinePool.get_free();
if (pipeLine == nullptr)
{
LOG_WARN << "can't get free pipeline";
@@ -56,24 +120,29 @@
return false;
}
+ PoolElemLocker<PipeLinePool*, PipeLine*> _lock_pipeLine(&g_PipeLinePool, pipeLine);
+
// fill
- MB_Frame frame;
- frame.type = (MB_Frame::MBFType)(fdpImage->mb_type);
- frame.buffer = fdpImage->buff;
- frame.buffSize = client.recvBuffSize - sizeof(EVPHeader) - sizeof(FDP_Image);
- frame.width = fdpImage->width;
- frame.height = fdpImage->height;
-
+ SensetimeFaceDetectDbFrame dbFrame;
+ dbFrame.type = (MB_Frame::MBFType)(fdpImage->mb_type);
+ dbFrame.buffSize = client.recvBuffSize - sizeof(EVPHeader) - sizeof(FDP_Image);
+ dbFrame.buffer = new uint8_t[dbFrame.buffSize];
+ ArrayDeleter<uint8_t*> _del_img((uint8_t*)dbFrame.buffer);
+ memcpy(dbFrame.buffer, fdpImage->buff, dbFrame.buffSize);
+ dbFrame.width = fdpImage->width;
+ dbFrame.height = fdpImage->height;
+ dbFrame.school_id = fdpImage->school_id;
+ dbFrame._faceAPI = _faceAPI;
+
PipeMaterial pm;
pm.type = PipeMaterial::PMT_FRAME;
- pm.buffer = &frame;
+ pm.buffer = &dbFrame;
pm.buffSize = 0;
PipeLineElem* plElem = pipeLine->pipe(&pm);
if (! pipeLine->check_pipe_complete(plElem))
{
LOG_WARN << "pipeline not complete";
- g_PipeLinePool.release(pipeLine);
ev_send_status_packet(client, EVPStatus::EVPS_INTERNAL_ERROR);
return false;
}
@@ -81,14 +150,13 @@
if (!plElem->gain(pm))
{
LOG_WARN << "pipeline gain error";
- g_PipeLinePool.release(pipeLine);
ev_send_status_packet(client, EVPStatus::EVPS_INTERNAL_ERROR);
return false;
}
- send_SensetimeFaceDetectResult(pm);
-
- g_PipeLinePool.release(pipeLine);
+ // can not release pipleline unless pm not used
+ send_SensetimeFaceDetectResult(client, pm);
+
return false;
}
@@ -132,7 +200,7 @@
{
PL_Payer_Config config;
- config.copyData = true;
+ config.copyData = true;//#todo false
PL_Gainer* ple = (PL_Gainer*)pipeLine->push_elem("PL_Gainer");
bool ret = ple->init(&config);
if (!ret)
--
Gitblit v1.8.0