From bf5edb317dcbf7ba1174968866aa8296637b3a58 Mon Sep 17 00:00:00 2001
From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期一, 17 四月 2017 14:21:14 +0800
Subject: [PATCH] decode bug fix
---
RtspFace/PL_SensetimeFaceDetect.cpp | 95 +++++++++++++++++++++++++++++++++--------------
1 files changed, 67 insertions(+), 28 deletions(-)
diff --git a/RtspFace/PL_SensetimeFaceDetect.cpp b/RtspFace/PL_SensetimeFaceDetect.cpp
index 5df118c..db9c257 100644
--- a/RtspFace/PL_SensetimeFaceDetect.cpp
+++ b/RtspFace/PL_SensetimeFaceDetect.cpp
@@ -1,20 +1,20 @@
#include "PL_SensetimeFaceDetect.h"
+#include "MaterialBuffer.h"
+#include "logger.h"
+#include "SensetimeFaceAPIWrapper/src/FaceDBPool.h"
+#include "SensetimeFaceAPIWrapper/src/faceAPI.h"
#include <opencv2/opencv.hpp>
#include <cv_face.h>
struct PL_SensetimeFaceDetect_Internal
{
- uint8_t buffer[1920*1080*4];
- size_t buffSize;
- size_t buffSizeMax;
- MB_Frame lastFrame;
-
bool payError;
+ PL_SensetimeFaceDetectConfig config;
+ SensetimeFaceDetectResult lastResult;
PL_SensetimeFaceDetect_Internal() :
- buffSize(0), buffSizeMax(sizeof(buffer)), lastFrame(),
- payError(true)
+ payError(true), config(), lastResult()
{
}
@@ -24,11 +24,13 @@
void reset()
{
- buffSize = 0;
payError = true;
- MB_Frame _lastFrame;
- lastFrame = _lastFrame;
+ PL_SensetimeFaceDetectConfig _config;
+ config = _config;
+
+ SensetimeFaceDetectResult _lastResult;
+ lastResult = _lastResult;
}
};
@@ -52,46 +54,70 @@
PL_SensetimeFaceDetect_Internal* in = (PL_SensetimeFaceDetect_Internal*)internal;
in->reset();
+ if (args != nullptr)
+ {
+ PL_SensetimeFaceDetectConfig* config = (PL_SensetimeFaceDetectConfig*)args;
+ in->config = *config;
+ }
+
return true;
}
void PL_SensetimeFaceDetect::finit()
{
PL_SensetimeFaceDetect_Internal* in = (PL_SensetimeFaceDetect_Internal*)internal;
-
+
}
bool PL_SensetimeFaceDetect::pay(const PipeMaterial& pm)
{
PL_SensetimeFaceDetect_Internal* in = (PL_SensetimeFaceDetect_Internal*)internal;
-
- if (pm.type != PipeMaterial::PMT_FRAME)
+
+ in->payError = true;
{
- printf("PL_H264Encoder::pay only support PMT_FRAME\n");
+ SensetimeFaceDetectResult _lastResult;
+ in->lastResult = _lastResult;
+ }
+
+ if (pm.type != PipeMaterial::PMT_FRAME || !(in->config.payWithDbFrame))
+ {
+ LOG_ERROR << "Only support PMT_FRAME (SensetimeFaceDetectDbFrame)" << std::endl;
return false;
}
if (pm.buffer == nullptr)
return false;
- MB_Frame* frame = (MB_Frame*)pm.buffer;
+ SensetimeFaceDetectDbFrame* frame = (SensetimeFaceDetectDbFrame*)pm.buffer;
if (frame->type != MB_Frame::MBFT_YUV420)
{
- printf("PL_H264Encoder::pay only support MBFT_YUV420\n");
+ LOG_ERROR << "Only support MBFT_YUV420" << std::endl;
return false;
}
+ FaceDB* _faceDB = (FaceDB*)frame->_faceDB;
+ if (_faceDB == nullptr)
+ {
+ LOG_ERROR << "FaceDB is null" << std::endl;
+ return false;
+ }
+ const size_t expectedYUVSize = frame->width * frame->height * 1.5;
+ if (frame->buffSize < expectedYUVSize)
+ {
+ LOG_WARN << "image size not ok" << std::endl;
+ return false;
+ }
- //in->buffer readly
-
- //static size_t f=0;
- //char fname[50];
- //sprintf(fname, "%u.bgra", ++f);
- //FILE * pFile = fopen (fname,"wb");
- //fwrite (in->buffer , sizeof(char), in->buffSize, pFile);
- //fclose(pFile);
-
+ cv::Mat yuvMat(cv::Size(frame->width,frame->height), CV_8UC3, frame->buffer);
+ cv_feature_t* feature = _faceDB->extract_feature(yuvMat);
+ in->lastResult.st_id = _faceDB->search_db(feature);
+ //in->lastResult.st_id = _faceDB->do_reasch(yuvMat);
+ //#todo release feature
+
+ in->lastResult.school_id = frame->school_id;
+
+ in->payError = false;
return true;
}
@@ -99,9 +125,22 @@
{
PL_SensetimeFaceDetect_Internal* in = (PL_SensetimeFaceDetect_Internal*)internal;
- pm.type = PipeMaterial::PMT_FRAME;
- pm.buffer = (uint8_t*)(&(in->lastFrame));
- pm.buffSize = sizeof(in->lastFrame);
pm.former = this;
+
+ if (in->payError)
+ {
+ return false;
+ }
+
+ if (! in->config.resultStructOnly)
+ {
+ LOG_ERROR << "Only support resultStructOnly" << std::endl;
+ return false;
+ }
+
+ pm.type = PipeMaterial::PMT_BYTES;
+ pm.buffer = &(in->lastResult);
+ pm.buffSize = sizeof(SensetimeFaceDetectResult);
+
return true;
}
--
Gitblit v1.8.0