houxiao
2017-04-12 a338cd531c460c0b3e829217f1f91f0156bcc6a7
VisitFace/RtspNativeCodec/app/src/main/cpp/FaceCache.cpp
@@ -171,7 +171,7 @@
    return buffMaxSize > 0;
}
bool FaceCache::getFaceListImage(int* buffIdx, size_t& count, uint8_t* buffImg, size_t& buffImgMaxSize)
bool FaceCache::getFaceListImage(std::vector<NativeImgIdx>& imgIdxes, uint8_t* buffImg, size_t& buffImgMaxSize)
{
    FcPmBreackerContext& ctx(*(FcPmBreackerContext*)_ctx);
@@ -181,31 +181,36 @@
        if (! ctx.convertYUV420ToRGB())
            return false;
    }
   count = 0;
   uint8_t* pBuff = buffImg;
   size_t totalSize = 0;
    imgIdxes.clear();
   size_t offset = 0;
    cv::Mat rgbMat(cv::Size(ctx.width, ctx.height), CV_8UC3, ctx.frameRGB);
    for (st_ff_vect_t::const_iterator ffiter = ctx.faceFeatures.begin(); ffiter != ctx.faceFeatures.end(); ++ffiter)
    {
        const FaceRect& faceRect(ffiter->rect);
        cv::Mat roiMat(rgbMat, cv::Rect(faceRect.leftTop.x, faceRect.leftTop.y, faceRect.rightBottom.x - faceRect.leftTop.x, faceRect.rightBottom.y - faceRect.leftTop.y));
        NativeImgIdx imgidx;
        imgidx.offset = offset;
        imgidx.size = roiMat.total() * roiMat.elemSize();
        imgidx.type = MB_Frame::MBFT_RGB;
        imgidx.width = roiMat.cols;
        imgidx.height = roiMat.rows;
        const size_t newSize = imgidx.offset + imgidx.size;
      //isContinuous
      size_t s = roiMat.total() * roiMat.elemSize();
      if (totalSize + s <= buffImgMaxSize)
      {
         memcpy(pBuff, roiMat.ptr(), s);
         *buffIdx = int(totalSize);
         pBuff += s;
         totalSize += s;
         count++;
         buffIdx++;
      }
      if (newSize > buffImgMaxSize)
        {
            LOG_ERROR << "FaceCache::getFaceListImage buffImgMaxSize truncated" << LOG_ENDL;
            return false;
        }
        memcpy(buffImg + imgidx.offset, roiMat.ptr(), imgidx.size);
        imgIdxes.push_back(imgidx);
        offset = newSize;
    }
    buffImgMaxSize = totalSize;
    return (count != 0);
    return true;
}