houxiao
2017-04-11 a05971bb73cced9426e11e26708a3f3cd2c3fc17
VisitFace/RtspNativeCodec/app/src/main/cpp/FaceCache.cpp
@@ -13,6 +13,8 @@
#include "PbFaceList.pb.h"
#include <libyuv.h>
struct FcPmBreackerContext
{
   uint8_t frameYUV[1920*1080*4];
@@ -46,6 +48,21 @@
   
   bool convertYUV420ToRGB()
   {
#define SUBSAMPLE(v, a) ((((v) + (a) - 1)) / (a))
        int src_height = height;
        int src_width = width;
        const uint8* src_y = (const uint8*)(frameYUV);
        const uint8* src_u = (const uint8*)(src_y + (src_height * src_width));
        const uint8* src_v = (const uint8*)(src_u + (src_height * src_width / 4));
        libyuv::I420ToRGB24(src_y, src_width,
                           src_u, SUBSAMPLE(src_width, 2),
                           src_v, SUBSAMPLE(src_width, 2),
                           frameRGB, 3 * src_width,
                           src_width, src_height);
        frameRGBSize = src_height * src_width * 3;
        return true;
   }
};
@@ -58,7 +75,7 @@
   ctx->faceFeatures = faceFeatures;
   
   ctx->dataAvailable &= true;
   return false;
   return true;
}
bool fc_pm_breaker_frame(const PipeMaterial* pm, void* args)
@@ -84,7 +101,7 @@
   memcpy(ctx->frameYUV, lastFrame->buffer, ctx->frameYUVSize);
   
   ctx->dataAvailable &= true;
   return false;
   return true;
}
#ifdef USE_ST_SDK
@@ -119,9 +136,12 @@
bool FaceCache::getFaceListPb(uint8_t* buffer, size_t& buffMaxSize)
{
    FcPmBreackerContext& ctx(*(FcPmBreackerContext*)_ctx);
    if (!ctx.dataAvailable)
        return false;
   
   PbFaceList pbFaceList;
   pbFaceList.set_image_count(ctx.faceFeatures.size());
    pbFaceList.set_magic(pbFaceList.magic());
    pbFaceList.set_image_count(ctx.faceFeatures.size());
   pbFaceList.set_src_width(ctx.width);
   pbFaceList.set_src_height(ctx.height);
   
@@ -141,11 +161,14 @@
      pbFaceListImage.set_top_left_x(faceRect.leftTop.x);
      pbFaceListImage.set_top_left_y(faceRect.leftTop.y);
      
      pbFaceListImage.set_img(0, roiMat.ptr(), roiMat.elemSize());
      pbFaceListImage.add_img(roiMat.ptr(), roiMat.total() * roiMat.elemSize());
    }
   size_t s = pbFaceList.ByteSize();
   buffMaxSize = std::min(s, buffMaxSize);
   pbFaceList.SerializeToArray(buffer, buffMaxSize);
    return false;
    return buffMaxSize > 0;
}
bool FaceCache::getFaceListImage(int* buffIdx, size_t& count, uint8_t* buffImg, size_t& buffImgMaxSize)
@@ -154,6 +177,7 @@
    if (ctx.frameRGBSize == 0)
    {
        //#todo should optimize not convert the whole image
        if (! ctx.convertYUV420ToRGB())
            return false;
    }
@@ -169,7 +193,7 @@
        cv::Mat roiMat(rgbMat, cv::Rect(faceRect.leftTop.x, faceRect.leftTop.y, faceRect.rightBottom.x - faceRect.leftTop.x, faceRect.rightBottom.y - faceRect.leftTop.y));
      
      //isContinuous
      size_t s = roiMat.elemSize();
      size_t s = roiMat.total() * roiMat.elemSize();
      if (totalSize + s <= buffImgMaxSize)
      {
         memcpy(pBuff, roiMat.ptr(), s);
@@ -182,5 +206,6 @@
      }
    }
    buffImgMaxSize = totalSize;
    return (count != 0);
}