chenke
2017-07-20 1eb1ffa329352dbbd4c5d6cf3e1ef08272e31957
VisitFace/RtspNativeCodec/app/src/main/cpp/CameraWrapper.cpp
@@ -1,12 +1,13 @@
#include "CameraWrapper.h"
#include "CameraWrapper.h"
#include <logger.h>
#include <Logger/src/logger.hpp>
#include <PL_Gainer.h>
#include <PL_Paint.h>
#include <PL_Scale.h>
#include <MaterialBuffer.h>
#include <PL_V4L2Source.h>
#include <PL_BlockGrouping.h>
#include <PL_ColorConv.h>
CameraWrapper::~CameraWrapper()
{
   stop();
@@ -68,10 +69,11 @@
    PipeLine::register_global_elem_creator("PL_AndroidSurfaceViewRender", create_PL_AndroidSurfaceViewRender);
    PipeLine::register_global_elem_creator("PL_SensetimeFaceTrack", create_PL_SensetimeFaceTrack);
    PipeLine::register_global_elem_creator("PL_Gainer", create_PL_Gainer);
    PipeLine::register_global_elem_creator("PL_Scale", create_PL_Scale);
    PipeLine::register_global_elem_creator("PL_ColorConv", create_PL_ColorConv);
    PipeLine::register_global_elem_creator("PL_Paint", create_PL_Paint);
    PipeLine::register_global_elem_creator("PL_V4L2Source", create_PL_V4L2Source);
    PipeLine::register_global_elem_creator("PL_BlockGrouping", create_PL_BlockGrouping);
    bool ret = false;
    {
@@ -120,7 +122,7 @@
            return  false;
        }
        PL_Gainer* plBG = (PL_Gainer*)pipeLineAnalyzer->push_elem("PL_BlockGrouping");
        PL_BlockGrouping* plBG = (PL_BlockGrouping*)pipeLineAnalyzer->push_elem("PL_BlockGrouping");
        PL_BlockGrouping_Config plbgConfig;
        plbgConfig.user_score_2_func = pl_analizer_plbg_user_score_2_func;
        plbgConfig.get_rect_func = pl_analizer_plbg_get_rect_func;
@@ -141,7 +143,37 @@
            return  false;
        }
        ANativeWindow* window = (ANativeWindow*)(windowRender);
        ANativeWindow_Buffer buffer;
        if(windowRender != nullptr && ANativeWindow_lock(window, &buffer, NULL) == 0)
        {
            plScaleCfg.toHeight=buffer.height;
            plScaleCfg.toWidth=buffer.width;
            ANativeWindow_unlockAndPost(window);
        } else
        {
            plScaleCfg.toHeight=480;
            plScaleCfg.toWidth=640;
        }
        PL_Scale* plScale = (PL_Scale*)pipeLineRender->push_elem("PL_Scale");
        ret = plScale->init(&plScaleCfg);
        if (!ret)
        {
            LOG_ERROR << "pipeLineRender.plScale init error" << LOG_ENDL;
            return  false;
        }
        PL_ColorConv_Config PLColorConvCfg;
        PL_ColorConv* plColorConv = (PL_ColorConv*)pipeLineRender->push_elem("PL_ColorConv");
        ret = plColorConv->init(&PLColorConvCfg);
        if (!ret)
        {
            LOG_ERROR << "pipeLineRender.plPaint init error" << LOG_ENDL;
            return  false;
        }
        PL_Paint_Config plPaintCfg;
        plPaintCfg.fontPath = "data/msyh.ttc";
        plPaintCfg.plplCtx = &plplContext;
        PL_Paint* plPaint = (PL_Paint*)pipeLineRender->push_elem("PL_Paint");
        ret = plPaint->init(&plPaintCfg);
@@ -201,6 +233,9 @@
    plplContext.cmds.clear();
    plplContext.params.clear();
    float width_scale =((float)cameraWrapper.plScaleCfg.toWidth) / cameraWrapper.amcdConfig.ak_width;
    float height_scale =((float)cameraWrapper.plScaleCfg.toHeight) / cameraWrapper.amcdConfig.ak_height;
    for (st_ff_vect_t::const_iterator iter = faceFeatures.begin(); iter != faceFeatures.end(); ++iter)
    {
        plplContext.cmds.push_back(PLPLC_COLOR);
@@ -231,18 +266,18 @@
        }
        plplContext.cmds.push_back(PLPLC_RECT);
        plplContext.params.push_back(iter->rect.leftTop.X);
        plplContext.params.push_back(iter->rect.leftTop.Y);
        plplContext.params.push_back(iter->rect.rightBottom.X);
        plplContext.params.push_back(iter->rect.rightBottom.Y);
        plplContext.params.push_back((int)(iter->rect.leftTop.X * width_scale));
        plplContext.params.push_back((int)(iter->rect.leftTop.Y * height_scale));
        plplContext.params.push_back((int)(iter->rect.rightBottom.X * width_scale));
        plplContext.params.push_back((int)(iter->rect.rightBottom.Y * height_scale));
        std::map<int, std::string>::iterator iterFaceLabel = cameraWrapper.faceLabels.find(iter->id);
        std::map<int, std::wstring>::iterator iterFaceLabel = cameraWrapper.faceLabels.find(iter->id);
        if (iterFaceLabel != cameraWrapper.faceLabels.end())
        {
            plplContext.cmds.push_back(PLPLC_TEXT);
            plplContext.params.push_back(iter->rect.leftTop.X);
            plplContext.params.push_back(iter->rect.leftTop.Y);
            const char* label = iterFaceLabel->second.c_str();
            plplContext.cmds.push_back(PLPLC_WTEXT);
            plplContext.params.push_back((int)(iter->rect.leftTop.X * width_scale));
            plplContext.params.push_back((int)(iter->rect.leftTop.Y * height_scale));
            const wchar_t* label = iterFaceLabel->second.c_str();
            plplContext.params.push_back(PLPLType(label));
        }
    }
@@ -269,21 +304,45 @@
void test_paint(CameraWrapper& cameraWrapper)
{
    cameraWrapper.setFaceLabel(0, "vip");
    cameraWrapper.setFaceLabel(1, "abc");
    cameraWrapper.setFaceLabel(2, "wrn");
    cameraWrapper.plplContext.cmds.push_back(PLPLC_WTEXT);
    cameraWrapper.plplContext.params.push_back(100);
    cameraWrapper.plplContext.params.push_back(100);
    cameraWrapper.plplContext.params.push_back(PLPLType(L"中文是啊"));
    cameraWrapper.setFaceLabel(0, L"会员vi");
    cameraWrapper.setFaceLabel(1, L"会员ab");
    cameraWrapper.setFaceLabel(3, L"会员wr");
    cameraWrapper.setFaceLabel(4, L"会员wr");
    cameraWrapper.setFaceLabel(5, L"会员wn");
    cameraWrapper.setFaceLabel(6, L"会员wr");
    cameraWrapper.setFaceLabel(7, L"会员wn");
    cameraWrapper.setFaceLabel(8, L"会员wr");
    cameraWrapper.setFaceLabel(9, L"会员wr");
    cameraWrapper.setFaceLabel(10, L"会员wn");
    cameraWrapper.setFaceLabel(11, L"会员wr");
    cameraWrapper.setFaceLabel(12, L"会员wr");
    cameraWrapper.setFaceLabel(13, L"会员wr");
    cameraWrapper.setFaceLabel(14, L"会员wr");
    cameraWrapper.setFaceLabel(15, L"会员wr");
    cameraWrapper.setFaceLabel(16, L"会员wn");
    cameraWrapper.setFaceLabel(17, L"会员wr");
    cameraWrapper.setFaceLabel(18, L"会员wr");
    cameraWrapper.setFaceLabel(19, L"会员wr");
    cameraWrapper.setFaceLabel(20, L"会员wr");
    cameraWrapper.setFaceLabel(21, L"会员wr");
    cameraWrapper.setFaceLabel(22, L"会员wr");
    cameraWrapper.plplContext.cmds.push_back(PLPLC_COLOR);
    cameraWrapper.plplContext.params.push_back('F');
    cameraWrapper.plplContext.params.push_back(255);
    cameraWrapper.plplContext.params.push_back(0);
    cameraWrapper.plplContext.params.push_back(0);
    cameraWrapper.plplContext.params.push_back(255);
    cameraWrapper.plplContext.cmds.push_back(PLPLC_RECT);
    cameraWrapper.plplContext.params.push_back(20);
    cameraWrapper.plplContext.params.push_back(20);
    cameraWrapper.plplContext.params.push_back(100);
    cameraWrapper.plplContext.params.push_back(100);
    cameraWrapper.plplContext.params.push_back(255);
    cameraWrapper.plplContext.params.push_back(255);
//    cameraWrapper.plplContext.cmds.push_back(PLPLC_RECT);
//    cameraWrapper.plplContext.params.push_back(20);
//    cameraWrapper.plplContext.params.push_back(20);
//    cameraWrapper.plplContext.params.push_back(100);
//    cameraWrapper.plplContext.params.push_back(100);
}
/*static*/ void* CameraWrapper::decoder_thd(void* arg)
@@ -336,7 +395,7 @@
   faceCacheLocked = false;
}
void CameraWrapper::setFaceLabel(int st_track_id, const std::string& label)
void CameraWrapper::setFaceLabel(int st_track_id, const std::wstring& label)
{
    if (faceLabels.size() > 32)
        faceLabels.clear();