chenke
2017-07-27 bf74ac0583bc8102654cd04e7389224419f3ba90
商汤人脸检测拆分多线程

git-svn-id: http://192.168.1.226/svn/proxy@925 454eff88-639b-444f-9e54-f578c98de674
2个文件已添加
8个文件已修改
777 ■■■■ 已修改文件
RtspFace/PL_BlockGrouping.cpp 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
RtspFace/PL_SensetimeFaceTrackMitiTrd.cpp 480 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
RtspFace/PL_SensetimeFaceTrackMitiTrd.h 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/cpp/CMakeLists.txt 150 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/cpp/CameraWrapper.cpp 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/cpp/CameraWrapper.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/cpp/CaptureCamera.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/cpp/FaceCache.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/cpp/RtspNativeCodecJNI.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
VisitFace/RtspNativeCodec/app/src/main/java/com/example/nativecodec/NativeCodec.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
RtspFace/PL_BlockGrouping.cpp
@@ -576,8 +576,8 @@
            
            if (calc_canny)
            {
                float cannyScore = scoring_canny_focus(*iterBlk) * 10.0f;
                totalScore += in->config.canny_focus * cannyScore;
                //float cannyScore = scoring_canny_focus(*iterBlk) * 10.0f;
                //totalScore += in->config.canny_focus * cannyScore;
            }
            if (calc_histogram)
            {
RtspFace/PL_SensetimeFaceTrackMitiTrd.cpp
New file
@@ -0,0 +1,480 @@
#include "PL_SensetimeFaceTrackMitiTrd.h"
#include "MaterialBuffer.h"
#include "logger.h"
#include "MediaHelper.h"
#ifdef USE_OPENCV
#include <opencv2/opencv.hpp>
#endif
#include <cv_face.h>
class SensetimeFaceTrackThread {
public:
    SensetimeFaceTrackThread():
                                image_width(0), image_height(0),
                                image_stride(0),track_result(CV_OK),
                                thread_running(false) , buffer_updated(false),
                                image(nullptr),is_busy(true),config(),
                                buffer_size(0), res_updated(false)
    {
    }
    ~SensetimeFaceTrackThread() {
        thread_running = false;
        pthread_mutex_unlock(&thd_mutex);
        pthread_join(track_thid, nullptr);
        pthread_mutex_destroy(&thd_mutex);
        pthread_mutex_destroy(&res_mutex);
        cv_face_destroy_tracker(tracker_handle);
        delete(image);
        image = nullptr;
    }
    int initial(){
        int ret = pthread_create(&track_thid, NULL, track_thread, this);
        if (ret != 0) {
            LOGP(ERROR, "pthread_create: %s/n", strerror(ret));
            thread_running = false;
            return ret;
        } else {
            thread_running = true;
        }
        ret = pthread_mutex_init(&thd_mutex, nullptr);
        if (ret != 0) {
            LOGP(ERROR, "pthread_mutex_init thd_mutex: %s/n", strerror(ret));
            thread_running = false;
            return ret;
        }
        ret = pthread_mutex_init(&res_mutex, nullptr);
        if (ret != 0) {
            LOGP(ERROR, "pthread_mutex_init res_mutex: %s/n", strerror(ret));
            thread_running = false;
            return ret;
        }
        ret = cv_face_create_tracker(&tracker_handle, nullptr, config.point_size_config);
        if (ret != 0) {
            LOGP(ERROR, "cv_face_create_tracker: %s/n", strerror(ret));
            thread_running = false;
            return ret;
        }
        ret = cv_face_track_set_detect_face_cnt_limit(tracker_handle, config.detect_face_cnt_limit, nullptr);
        if (ret != 0) {
            LOGP(ERROR, "cv_face_track_set_detect_face_cnt_limit: %s/n", strerror(ret));
            thread_running = false;
            return ret;
        }
        return ret;
    }
    void do_face_track(
            const unsigned char *image,
            cv_pixel_format pixel_format,
            int image_width,
            int image_height,
            int image_stride,
            cv_face_orientation orientation = CV_FACE_UP
    ) {
        if(is_busy)return;
        copy_image(image, image_height, image_stride);
        this->pixel_format = pixel_format;
        this->image_width = image_width;
        this->image_height = image_height;
        this->image_stride = image_stride;
        this->orientation = orientation;
        buffer_updated =true;
        int ret = pthread_mutex_unlock(&thd_mutex);
        if (ret != 0) {
            LOGP(ERROR, "pthread_mutex_unlock: %s/n", strerror(ret));
            thread_running = false;
        }
    }
    int initial_license(char *path) {
        int res = 0;
        FILE *licFile = fopen(path, "rb");
        if (licFile != nullptr) {
            char licBuffer[1025 * 5] = {'\0'};
            size_t licSize = fread(licBuffer, sizeof(uint8_t), sizeof(licBuffer), licFile);
            fclose(licFile);
            if (licSize > 0) {
                res = cv_face_init_license_config(licBuffer);
                LOG_INFO << "cv_face_init_license_config 1 ret=" << res << LOG_ENDL;
                return res;
            }
        } else {
            LOG_WARN << "cv_face_init_license_config 2 errno=" << errno << LOG_ENDL;
            res = errno;
            return res;
        }
        return res;
    }
    void set_config(SensetimeFaceTrackConfig& cfg){
        config = cfg;
    }
    const SensetimeFaceTrackConfig* get_config(){
        return &config;
    }
private:
    pthread_t track_thid;
    pthread_mutex_t thd_mutex;
    pthread_mutex_t res_mutex;
    mutable volatile bool thread_running;
    mutable volatile bool buffer_updated;
    mutable volatile bool res_updated;
    mutable volatile bool is_busy;
private:
    static void *track_thread(void *Args) {
        SensetimeFaceTrackThread* tracker = (SensetimeFaceTrackThread*)Args;
        while(tracker->thread_running)
        {
            tracker->is_busy = false;
            int ret = pthread_mutex_lock(&tracker->thd_mutex);
            tracker->is_busy = true;
            if (ret != 0) {
                LOGP(ERROR, "pthread_mutex_lock: %s/n", strerror(ret));
                tracker->thread_running = false;
                break;
            }
            if(!tracker->buffer_updated)
                continue;
            tracker->track_result = cv_face_track(tracker->tracker_handle , tracker->image,
                                                  tracker->pixel_format, tracker->image_width,
                                                  tracker->image_height, tracker->image_stride,
                                                  tracker->orientation, &tracker->p_faces,
                                                  &tracker->faces_count);
            if (ret != 0) {
                LOGP(ERROR, "cv_face_track: %s/n", strerror(ret));
                tracker->thread_running = false;
                break;
            }
            ret = pthread_mutex_lock(&tracker->res_mutex);
            if (ret != 0) {
                LOGP(ERROR, "pthread_mutex_lock res_mutex: %s/n", strerror(ret));
                tracker->thread_running = false;
                break;
            }
            tracker->extract_features();
            ret = pthread_mutex_unlock(&tracker->res_mutex);
            if (ret != 0) {
                LOGP(ERROR, "pthread_mutex_unlock res_mutex: %s/n", strerror(ret));
                tracker->thread_running = false;
                break;
            }
            cv_face_release_tracker_result(tracker->p_faces, tracker->faces_count);
            tracker->buffer_updated = false;
        }
    }
    void copy_image(const unsigned char *src, int height, int stride){
        int size = height * stride * 1.5;
        if(image_size() < size){
            if(image != nullptr){
                delete(image);
            }
            image = new unsigned char[size];
            buffer_size = size;
        }
        memcpy(image, src, size);
    }
    int image_size(){
        return buffer_size;
    }
private:
    st_ff_vect_t faceFeatures;
    cv_handle_t tracker_handle;
    void extract_features(){
        faceFeatures.clear();
        for (int i = 0; i < faces_count; i++) {
            if (MH_F_LT(p_faces[i].score, config.score_min)) {
                continue;
            }
            SensetimeFaceFeature faceFeature;
            faceFeature.rect.leftTop.X = p_faces[i].rect.left;
            faceFeature.rect.leftTop.Y = p_faces[i].rect.top;
            faceFeature.rect.rightBottom.X = p_faces[i].rect.right;
            faceFeature.rect.rightBottom.Y = p_faces[i].rect.bottom;
            faceFeature.id = p_faces[i].ID;
            faceFeature.score = p_faces[i].score;
            faceFeature.yaw = p_faces[i].yaw;
            faceFeature.pitch = p_faces[i].pitch;
            faceFeature.roll = p_faces[i].roll;
            faceFeature.eyeDistance = p_faces[i].eye_dist;
            LOGP(DEBUG, "face: %d-----[%d, %d, %d, %d]-----id: %d", i,
                 p_faces[i].rect.left, p_faces[i].rect.top,
                 p_faces[i].rect.right, p_faces[i].rect.bottom, p_faces[i].ID);
            LOGP(DEBUG, "face pose: [yaw: %.2f, pitch: %.2f, roll: %.2f, eye distance: %.2f]",
                 p_faces[i].yaw, p_faces[i].pitch, p_faces[i].roll, p_faces[i].eye_dist);
            for (int j = 0; j < p_faces[i].points_count; j++) {
                PLGH_Point featurePoint;
                featurePoint.X = p_faces[i].points_array[j].x;
                featurePoint.Y = p_faces[i].points_array[j].y;
                faceFeature.featurePoints.points.push_back(featurePoint);
            }
            if (config.generate_face_point) {
                if (faceFeature.rect.leftTop.X < 0 ||
                    faceFeature.rect.rightBottom.X > image_height ||
                    faceFeature.rect.leftTop.Y < 0 || faceFeature.rect.rightBottom.Y > image_width)
                    faceFeature.outOfFrame = true;
            }
            if (config.generate_face_feature) {
                if (config.evenWidthHeight) {
                    if (faceFeature.rect.leftTop.X % 2 != 0) faceFeature.rect.leftTop.X--;
                    if (faceFeature.rect.leftTop.Y % 2 != 0) faceFeature.rect.leftTop.Y--;
                    if (faceFeature.rect.rightBottom.X % 2 != 0) faceFeature.rect.rightBottom.X--;
                    if (faceFeature.rect.rightBottom.Y % 2 != 0) faceFeature.rect.rightBottom.Y--;
                }
                // explode the range
                if (config.explode_feature_rect_x != 0) {
                    faceFeature.rect.leftTop.X = clamp(
                            faceFeature.rect.leftTop.X - config.explode_feature_rect_x, 0,
                            faceFeature.rect.leftTop.X);
                    faceFeature.rect.rightBottom.X = clamp(
                            faceFeature.rect.rightBottom.X + config.explode_feature_rect_x,
                            faceFeature.rect.rightBottom.X, int(image_width - 1));
                }
                if (config.explode_feature_rect_y != 0) {
                    faceFeature.rect.leftTop.Y = clamp(
                            faceFeature.rect.leftTop.Y - config.explode_feature_rect_y, 0,
                            faceFeature.rect.leftTop.Y);
                    faceFeature.rect.rightBottom.Y = clamp(
                            faceFeature.rect.rightBottom.Y + config.explode_feature_rect_y,
                            faceFeature.rect.rightBottom.Y, int(image_height - 1));
                }
                faceFeatures.push_back(faceFeature);
                LOG_ERROR<<"Feature id: "<<faceFeature.id <<LOG_ERROR;
            }
        }
        res_updated = true;
    }
public:
    void get_face_features(st_ff_vect_t& res_vector){
        if(!res_updated) return;
        int ret = pthread_mutex_lock(&res_mutex);
        if (ret != 0) {
            LOGP(ERROR, "pthread_mutex_lock res_mutex: %s/n", strerror(ret));
            thread_running = false;
        }
        res_vector = faceFeatures;
        ret = pthread_mutex_unlock(&res_mutex);
        res_updated = false;
        if (ret != 0) {
            LOGP(ERROR, "pthread_mutex_unlock res_mutex: %s/n", strerror(ret));
            thread_running = false;
        }
    }
private:
    unsigned char *image;
    cv_pixel_format pixel_format;
    int image_width;
    int image_height;
    int image_stride;
    int buffer_size;
    cv_face_orientation orientation;
    cv_face_t *p_faces;
    int faces_count;
    cv_result_t track_result;
    SensetimeFaceTrackConfig config;
};
struct PL_SensetimeFaceTrackMitiTrd_Internal {
    //uint8_t buffer[1920*1080*4];
    //size_t buffSize;
    //size_t buffSizeMax;
    MB_Frame lastFrame;
    PipeMaterial pmList[2];
    SensetimeFaceTrackThread trackThread;
    st_ff_vect_t faceFeatures;
    bool payError;
    size_t frameCount;
    PL_SensetimeFaceTrackMitiTrd_Internal() :
    //buffSize(0), buffSizeMax(sizeof(buffer)),
            lastFrame(), pmList(), frameCount(0) {
    }
    ~PL_SensetimeFaceTrackMitiTrd_Internal() {
    }
    void reset() {
        //buffSize = 0;
        payError = true;
        MB_Frame _lastFrame;
        lastFrame = _lastFrame;
        PipeMaterial _pm;
        pmList[0] = _pm;
        pmList[1] = _pm;
        frameCount = 0;
    }
};
PipeLineElem *create_PL_SensetimeFaceTrackMitiTrd() {
    return new PL_SensetimeFaceTrackMitiTrd;
}
PL_SensetimeFaceTrackMitiTrd::PL_SensetimeFaceTrackMitiTrd() : internal(
        new PL_SensetimeFaceTrackMitiTrd_Internal){
}
PL_SensetimeFaceTrackMitiTrd::~PL_SensetimeFaceTrackMitiTrd() {
    delete (PL_SensetimeFaceTrackMitiTrd_Internal *) internal;
    internal = nullptr;
    pthread_mutex_destroy(&pay_mutex);;
    pthread_mutex_destroy(&gain_mutex);
}
bool PL_SensetimeFaceTrackMitiTrd::init(void *args) {
    PL_SensetimeFaceTrackMitiTrd_Internal *in = (PL_SensetimeFaceTrackMitiTrd_Internal *) internal;
    in->reset();
    SensetimeFaceTrackConfig *config = (SensetimeFaceTrackConfig *) args;
    if (config->point_size == 21)
        config->point_size_config = CV_DETECT_ENABLE_ALIGN_21;
    else if (config->point_size == 106)
        config->point_size_config = CV_DETECT_ENABLE_ALIGN_106;
    else {
        LOG_ERROR << "alignment point size must be 21 or 106" << LOG_ENDL;
        return false;
    }
    int res = in->trackThread.initial_license("/data/license.lic");
    if(res!=0)return false;
    in->trackThread.set_config(*config);
    res = in->trackThread.initial();
    if(res!=0)return false;
    return true;
}
void PL_SensetimeFaceTrackMitiTrd::finit() {
    PL_SensetimeFaceTrackMitiTrd_Internal *in = (PL_SensetimeFaceTrackMitiTrd_Internal *) internal;
}
int doFaceTrack(PL_SensetimeFaceTrackMitiTrd_Internal *in,
                uint8_t *buffer, size_t width, size_t height, size_t stride,
                cv_pixel_format cvPixFmt) {
    PipeLineElemTimingDebugger td(nullptr);
    in->trackThread.do_face_track(buffer, cvPixFmt, width, height, stride);
    return 0;
}
/*static*/ bool
PL_SensetimeFaceTrackMitiTrd::pay_breaker_MBFT_YUV(const PipeMaterial *pm, void *args) {
    PL_SensetimeFaceTrackMitiTrd_Internal *in = (PL_SensetimeFaceTrackMitiTrd_Internal *) args;
    if (pm->type != PipeMaterial::PMT_FRAME) {
        LOG_ERROR << "Only support PMT_FRAME" << LOG_ENDL;
        return false;
    }
    if (pm->buffer == nullptr)
        return false;
    MB_Frame *frame = (MB_Frame *) pm->buffer;
    if (frame->type != MB_Frame::MBFT_YUV420 && frame->type != MB_Frame::MBFT_NV12) {
        LOG_ERROR << "Only support MBFT_YUV420 and MBFT_NV12" << LOG_ENDL;
        return false;
    }
    int res = 0;
    if (frame->type == MB_Frame::MBFT_YUV420)
        res = doFaceTrack(in, (uint8_t *) frame->buffer, frame->width, frame->height,
                                 frame->width, CV_PIX_FMT_YUV420P);
    else if (frame->type == MB_Frame::MBFT_NV12)
        res = doFaceTrack(in, (uint8_t *) frame->buffer, frame->width, frame->height,
                                 frame->width, CV_PIX_FMT_NV12);
    if (res < 0) {
        in->payError = true;
        return false;
    } else
        in->payError = false;
    //in->buffer readly
    in->lastFrame.type = frame->type;
    in->lastFrame.buffer = frame->buffer;//#todo should copy
    in->lastFrame.buffSize = frame->buffSize;
    in->lastFrame.width = frame->width;
    in->lastFrame.height = frame->height;
    in->lastFrame.pts = frame->pts;
    return false;
}
bool PL_SensetimeFaceTrackMitiTrd::pay(const PipeMaterial &pm) {
    PL_SensetimeFaceTrackMitiTrd_Internal *in = (PL_SensetimeFaceTrackMitiTrd_Internal *) internal;
    //LOG_ERROR << "PL_SensetimeFaceTrackMitiTrd pay" << LOG_ENDL;
    in->payError = true;
    if (in->payError)
        pm.breake(PipeMaterial::PMT_FRAME_LIST, MB_Frame::MBFT_YUV420,
                  PL_SensetimeFaceTrackMitiTrd::pay_breaker_MBFT_YUV, in);
    if (in->payError)
        pm.breake(PipeMaterial::PMT_FRAME_LIST, MB_Frame::MBFT_NV12,
                  PL_SensetimeFaceTrackMitiTrd::pay_breaker_MBFT_YUV, in);
    if (in->payError)
        pm.breake(PipeMaterial::PMT_FRAME, MB_Frame::MBFT_YUV420,
                  PL_SensetimeFaceTrackMitiTrd::pay_breaker_MBFT_YUV, in);
    if (in->payError)
        pm.breake(PipeMaterial::PMT_FRAME, MB_Frame::MBFT_NV12,
                  PL_SensetimeFaceTrackMitiTrd::pay_breaker_MBFT_YUV, in);
    in->frameCount++;
    return !(in->payError);
}
bool PL_SensetimeFaceTrackMitiTrd::gain(PipeMaterial &pm) {
    PL_SensetimeFaceTrackMitiTrd_Internal *in = (PL_SensetimeFaceTrackMitiTrd_Internal *) internal;
    in->trackThread.get_face_features(in->faceFeatures);
    if (in->payError) {
        pm.former = this;
        return false;
    }
    if (!in->trackThread.get_config()->generate_face_feature) {
        pm.type = PipeMaterial::PMT_FRAME;
        pm.buffer = &(in->lastFrame);
        pm.buffSize = 0;
    } else {
        in->pmList[0].type = PipeMaterial::PMT_FRAME;
        in->pmList[0].buffer = &(in->lastFrame);
        in->pmList[0].buffSize = 0;
        in->pmList[0].former = this;
        in->pmList[1].type = PipeMaterial::PMT_PTR;
        in->pmList[1].buffer = &(in->faceFeatures);
        in->pmList[1].buffSize = 0;
        in->pmList[1].former = this;
        pm.type = PipeMaterial::PMT_PM_LIST;
        pm.buffer = in->pmList;
        pm.buffSize = sizeof(in->pmList) / sizeof(PipeMaterial);
    }
    pm.former = this;
    return true;
}
void *PL_SensetimeFaceTrackMitiTrd::pay_thd(void *arg) {
}
RtspFace/PL_SensetimeFaceTrackMitiTrd.h
New file
@@ -0,0 +1,112 @@
#ifndef _PL_SensetimeFaceTrackMitiTrd_H_
#define _PL_SensetimeFaceTrackMitiTrd_H_
#include "PipeLine.h"
#include "GraphicHelper.h"
#include <vector>
#include <cmath>
struct SensetimeFaceFeature
{
    PLGH_Rect rect;
    int id;
    float score;
    /* Camera vision vector point to face
     *  * * *
     *  * * *
     *  * * *
     */
    float yaw;
    /* Camera vision vector point to face
     *  * * *
     *  * * *
     *  * * *
     */
    float pitch;
    /* Camera vision vector point to face
     *  * * *
     *  * * *
     *  * * *
     */
    float roll;
    float eyeDistance;
    PLGH_Path featurePoints;
    bool outOfFrame;
    SensetimeFaceFeature() :
        rect(), id(0), score(0.0), yaw(0.0), pitch(0.0), roll(0.0), eyeDistance(0.0), featurePoints(),
        outOfFrame(false)
    {}
    bool test_face_in_cone(float _yaw, float _pitch, float _roll) const
    {
        return  (std::abs(yaw) < _yaw && std::abs(pitch) < _pitch && std::abs(roll) < _roll);
    }
};
typedef std::vector<SensetimeFaceFeature> st_ff_vect_t;
struct SensetimeFaceTrackConfig
{
    int point_size; // 21 / 106
    int point_size_config; // CV_DETECT_ENABLE_ALIGN_21 / CV_DETECT_ENABLE_ALIGN_106
    int detect_face_cnt_limit; // -1
    bool draw_face_rect;
    bool draw_face_feature_point;
    bool generate_face_feature;
    bool generate_face_point;
    int explode_feature_rect_x;
    int explode_feature_rect_y;
    bool clamp_feature_rect; // clamp fr width and height
    int doTrackPerFrame;
    std::string license_file_path;
    std::string license_str;
    float visionConeAngle;
    bool evenWidthHeight;
    float score_min;
    SensetimeFaceTrackConfig() :
        point_size(21), point_size_config(-1), detect_face_cnt_limit(-1),
        draw_face_rect(true), draw_face_feature_point(true), generate_face_feature(false), generate_face_point(false),
        explode_feature_rect_x(0), explode_feature_rect_y(0),
        clamp_feature_rect(false), doTrackPerFrame(1),
        license_file_path(), license_str(),
        visionConeAngle(90.1), evenWidthHeight(true),
        score_min(0.0f)
    { }
};
class PL_SensetimeFaceTrackMitiTrd : public PipeLineElem
{
public:
    PL_SensetimeFaceTrackMitiTrd();
    virtual ~PL_SensetimeFaceTrackMitiTrd();
    virtual bool init(void* args);
    virtual void finit();
    virtual bool pay(const PipeMaterial& pm);
    virtual bool gain(PipeMaterial& pm);
private:
    static bool pay_breaker_MBFT_YUV(const PipeMaterial* pm, void* args);
private:
    static void* pay_thd(void *arg);
    void* internal;
    pthread_mutex_t pay_mutex;
    pthread_mutex_t gain_mutex;
};
PipeLineElem* create_PL_SensetimeFaceTrackMitiTrd();
#endif
VisitFace/RtspNativeCodec/app/src/main/cpp/CMakeLists.txt
@@ -1,60 +1,57 @@
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O3 -std=c++11 -DUSE_OPENCV -DUSE_ST_SDK -DANDROID_PLATFORM=android-22  -DANDROID_TOOLCHAIN=gcc -DANDROID_STL=gnustl_static  -Wall -UNDEBUG")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -std=c++11 -DUSE_OPENCV -DUSE_ST_SDK -DANDROID_PLATFORM=android-22  -DANDROID_TOOLCHAIN=gcc -DANDROID_STL=gnustl_static  -Wall -UNDEBUG")
#debug for video only test
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -std=c++11 -fno-rtti  -Wall -UNDEBUG")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -std=c++11 -DANDROID_PLATFORM=android-22  -DANDROID_TOOLCHAIN=gcc -DANDROID_STL=gnustl_static -Wall -UNDEBUG")
set(WORKSPACE_PATH "D:/workspace/proxy")
add_library(rtspface SHARED
            RtspNativeCodecJNI.cpp
            CameraWrapper.cpp
            FaceCache.cpp
            FaceCacheForPLBG.cpp
            DebugNetwork.cpp
            CaptureCamera.cpp
            cpu_sched_test.cpp
            serial.c
            TeleWrapper.cpp
            RtspNativeCodecJNI.cpp
            CameraWrapper.cpp
            FaceCache.cpp
            FaceCacheForPLBG.cpp
            DebugNetwork.cpp
            CaptureCamera.cpp
            serial.c
            cpu_sched_test.cpp
            TeleWrapper.cpp
            "D:/workspace/proxy/RtspFace/PipeLine.cpp"
            "D:/workspace/proxy/RtspFace/Logger/src/logger.cc"
            "D:/workspace/proxy/RtspFace/MediaHelper.cpp"
            "D:/workspace/proxy/RtspFace/GraphicHelper.cpp"
            "D:/workspace/proxy/RtspFace/PL_RTSPClient.cpp"
            "D:/workspace/proxy/RtspFace/PL_AndroidMediaCodecDecoder_ndk.cpp"
            "D:/workspace/proxy/RtspFace/PL_AndroidSurfaceViewRender.cpp"
            "D:/workspace/proxy/RtspFace/PL_SensetimeFaceTrack.cpp"
            "D:/workspace/proxy/RtspFace/PL_Gainer.cpp"
            "D:/workspace/proxy/RtspFace/PL_Scale.cpp"
            "D:/workspace/proxy/RtspFace/PL_ColorConv.cpp"
            "D:/workspace/proxy/RtspFace/PL_Paint.cpp"
            "D:/workspace/proxy/RtspFace/PL_V4L2Source.cpp"
            "D:/workspace/proxy/RtspFace/PL_BlockGrouping.cpp"
            #"D:/workspace/proxy/RtspFace/PL_Queue.cpp"
            #"D:/workspace/proxy/RtspFace/PL_Fork2.cpp"
            "D:/Documents/works/RtspFace/PL_Scale.cpp"
            "D:/Documents/works/RtspFace/PipeLine.cpp"
            "D:/Documents/works/RtspFace/Logger/src/logger.cc"
            "D:/Documents/works/RtspFace/MediaHelper.cpp"
            "D:/Documents/works/RtspFace/GraphicHelper.cpp"
            "D:/Documents/works/RtspFace/PL_RTSPClient.cpp"
            "D:/Documents/works/RtspFace/PL_AndroidMediaCodecDecoder_ndk.cpp"
            "D:/Documents/works/RtspFace/PL_AndroidSurfaceViewRender.cpp"
            "D:/Documents/works/RtspFace/PL_SensetimeFaceTrackMitiTrd.cpp"
            "D:/Documents/works/RtspFace/PL_ColorConv.cpp"
            "D:/Documents/works/RtspFace/PL_Gainer.cpp"
            "D:/Documents/works/RtspFace/PL_Paint.cpp"
            "D:/Documents/works/RtspFace/PL_V4L2Source.cpp"
            "D:/Documents/works/RtspFace/PL_BlockGrouping.cpp"
            "D:/Documents/works/RtspFace/PL_Queue.cpp"
            "D:/workspace/proxy/FaceServer/proto_hton_ntoh.cpp"
            "D:/workspace/proxy/FaceServer/PbFaceList.pb.cc"
            "D:/Documents/works/FaceServer/proto_hton_ntoh.cpp"
            "D:/Documents/works/FaceServer/PbFaceList.pb.cc"
             "D:/workspace/proxy/RtspFace/libv4l2cpp/src/V4l2Capture.cpp"
             "D:/workspace/proxy/RtspFace/libv4l2cpp/src/V4l2Device.cpp"
             "D:/workspace/proxy/RtspFace/libv4l2cpp/src/V4l2MmapDevice.cpp"
             "D:/workspace/proxy/RtspFace/libv4l2cpp/src/V4l2Output.cpp"
             "D:/Documents/works/RtspFace/libv4l2cpp/src/V4l2Capture.cpp"
             "D:/Documents/works/RtspFace/libv4l2cpp/src/V4l2Device.cpp"
             "D:/Documents/works/RtspFace/libv4l2cpp/src/V4l2MmapDevice.cpp"
             "D:/Documents/works/RtspFace/libv4l2cpp/src/V4l2Output.cpp"
            "D:/workspace/proxy/RtspFace/CvUtil/CvxText.cpp"
             "D:/Documents/works/RtspFace/CvUtil/CvxText.cpp"
            )
            )
# Include libraries needed for native-codec-jni lib
target_link_libraries(rtspface
                      android
                      log
                      #ui
                      mediandk
                      #OpenMAXAL
                      android
                      log
                      #ui
                      mediandk
                      #OpenMAXAL
                      #jnigraphics
                      #EGL
                      #GLESv2
@@ -62,51 +59,52 @@
                      )
include_directories(
                    "D:/workspace/proxy/RtspFace"
                    "D:/workspace/proxy/FaceServer"
                    "D:/Documents/works/RtspFace"
                    "D:/Documents/works/FaceServer"
                    #"D:/workspace/libhardware-android-5.1.1_r38/include"
                    #"D:/workspace/core-android-5.1.1_r38/include"
                    #"D:/workspace/native-android-5.1.1_r38/include"
                    #"D:/workspace/core-android-5.1.1_r38/libsync/include"
                    #"D:/workspace/native-android-5.1.1_r38/opengl/include"
                    #"D:/workspace/libhardware-android-5.1.1_r38/include"
                    #"D:/workspace/core-android-5.1.1_r38/include"
                    #"D:/workspace/native-android-5.1.1_r38/include"
                    #"D:/workspace/core-android-5.1.1_r38/libsync/include"
                    #"D:/workspace/native-android-5.1.1_r38/opengl/include"
                    "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/live555/include"
                    "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/live555/include/BasicUsageEnvironment"
                    "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/live555/include/groupsock"
                    "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/live555/include/liveMedia"
                    "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/live555/include/UsageEnvironment"
                    "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/live555/include"
                    "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/live555/include/BasicUsageEnvironment"
                    "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/live555/include/groupsock"
                    "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/live555/include/liveMedia"
                    "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/live555/include/UsageEnvironment"
                    "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/libyuv/include"
                    "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/libyuv/include"
                    "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/opencv/include"
                    "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/opencv/include"
                    "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/protobuf/include"
                    "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/protobuf/include"
                    "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/st_face/include"
                    "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/st_face/include"
                    "D:/workspace/proxy/RtspFace/libv4l2cpp/inc"
                    #"D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/libv4l2wrapper/include"
                    "D:/Documents/works/RtspFace/libv4l2cpp/inc"
                    "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/freetype/include/freetype2"
                    )
                    "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/freetype/include/freetype2"
                    #"D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/libv4l2wrapper/include"
                    )
target_link_libraries(rtspface
                      "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/live555/lib/armeabi-v7a/libliveMedia.a"
                      "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/live555/lib/armeabi-v7a/libgroupsock.a"
                      "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/live555/lib/armeabi-v7a/libBasicUsageEnvironment.a"
                      "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/live555/lib/armeabi-v7a/libUsageEnvironment.a"
                      "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/live555/lib/arm64-v8a/libliveMedia.a"
                      "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/live555/lib/arm64-v8a/libgroupsock.a"
                      "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/live555/lib/arm64-v8a/libBasicUsageEnvironment.a"
                      "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/live555/lib/arm64-v8a/libUsageEnvironment.a"
                      "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/libyuv/lib/armeabi-v7a/libyuv_static.a"
                      "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/opencv/lib/armeabi-v7a/libopencv_java3.so"
                      "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/protobuf/lib/armeabi-v7a/libprotobuf.so"
                      "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/st_face/lib/armeabi-v7a/libcvface_api.so"
                      "D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/freetype/lib/armeabi-v7a/libfreetype.so"
                      "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/libyuv/lib/arm64-v8a/libyuv_static.a"
                      "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/opencv/lib/arm64-v8a/libopencv_java3.so"
                      "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/protobuf/lib/arm64-v8a/libprotobuf.so"
                      "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/st_face/lib/arm64-v8a/libcvface_api.so"
                      "D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/freetype/lib/arm64-v8a/libfreetype.so"
                      #"D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/libv4l2wrapper/lib/armeabi-v7a/libv4l2wrapper.a"
                      #"D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/libv4l2wrapper/lib/arm64-v8a/libv4l2wrapper.a"
                      #"D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/android_sys/libgui.so"
                      #"D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/android_sys/libui.so"
                      #"D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/android_sys/libEGL.so"
                      #"D:/workspace/proxy/VisitFace/RtspNativeCodec/app/libs/android_sys/libGLESv3.so"
                      )
                      #"D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/android_sys/libgui.so"
                      #"D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/android_sys/libui.so"
                      #"D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/android_sys/libEGL.so"
                      #"D:/Documents/works/VisitFace/RtspNativeCodec/app/libs/android_sys/libGLESv3.so"
                      )
VisitFace/RtspNativeCodec/app/src/main/cpp/CameraWrapper.cpp
@@ -81,7 +81,8 @@
    PipeLine::register_global_elem_creator("PL_RTSPClient", create_PL_RTSPClient);
    PipeLine::register_global_elem_creator("PL_AndroidMediaCodecDecoder", create_PL_AndroidMediaCodecDecoder);
    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_SensetimeFaceTrack", create_PL_SensetimeFaceTrack);
    PipeLine::register_global_elem_creator("PL_SensetimeFaceTrackMitiTrd", create_PL_SensetimeFaceTrackMitiTrd);
    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);
@@ -197,7 +198,14 @@
    //}
#ifdef USE_ST_SDK
    PL_SensetimeFaceTrack *sfTrack = (PL_SensetimeFaceTrack *) pipeLineDecoderDetector->push_elem("PL_SensetimeFaceTrack");
//    PL_SensetimeFaceTrack *sfTrack = (PL_SensetimeFaceTrack *) pipeLineDecoderDetector->push_elem("PL_SensetimeFaceTrack");
//    ret = sfTrack->init(&sftConfig);
//    if (!ret)
//    {
//        LOG_ERROR << "pipeLineDecoderDetector.sfTrack.init error" << LOG_ENDL;
//        return false;
//    }
    PL_SensetimeFaceTrackMitiTrd *sfTrack = (PL_SensetimeFaceTrackMitiTrd *) pipeLineDecoderDetector->push_elem("PL_SensetimeFaceTrackMitiTrd");
    ret = sfTrack->init(&sftConfig);
    if (!ret)
    {
VisitFace/RtspNativeCodec/app/src/main/cpp/CameraWrapper.h
@@ -10,7 +10,7 @@
#include <PL_RTSPClient.h>
#include <PL_AndroidMediaCodecDecoder.h>
#include <PL_AndroidSurfaceViewRender.h>
#include <PL_SensetimeFaceTrack.h>
#include <PL_SensetimeFaceTrackMitiTrd.h>
#include <PL_Paint.h>
#include <PL_Scale.h>
//#include "looper.h"
VisitFace/RtspNativeCodec/app/src/main/cpp/CaptureCamera.h
@@ -5,7 +5,7 @@
#include <PL_RTSPClient.h>
#include <PL_AndroidMediaCodecDecoder.h>
#include <PL_AndroidSurfaceViewRender.h>
#include <PL_SensetimeFaceTrack.h>
#include <PL_SensetimeFaceTrackMitiTrd.h>
#include <PL_Paint.h>
#include <PL_Queue.h>
VisitFace/RtspNativeCodec/app/src/main/cpp/FaceCache.cpp
@@ -1,7 +1,7 @@
#include "FaceCache.h"
#include "PipeLine.h"
#include "MaterialBuffer.h"
#include "PL_SensetimeFaceTrack.h"
#include "PL_SensetimeFaceTrackMitiTrd.h"
#include <logger.h>
#include <Logger/src/logger.hpp>
VisitFace/RtspNativeCodec/app/src/main/cpp/RtspNativeCodecJNI.cpp
@@ -47,7 +47,7 @@
    cpu_sched();
#ifdef USE_ST_SDK
    PipeLine::register_global_elem_creator("PL_SensetimeFaceTrack", create_PL_SensetimeFaceTrack);
    PipeLine::register_global_elem_creator("PL_SensetimeFaceTrackMitiTrd", create_PL_SensetimeFaceTrackMitiTrd);
#endif
    for (size_t i = 0; i < CAMERA_COUNT; i++)
VisitFace/RtspNativeCodec/app/src/main/java/com/example/nativecodec/NativeCodec.java
@@ -23,6 +23,7 @@
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.util.Xml;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
@@ -82,11 +83,17 @@
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        ThisActivity = this;
        RtspFaceNative.init();
        RtspFaceNative.setLocalIP("192.168.1.82");
        for (int i=0 ;i < 32; i+=2){
            RtspFaceNative.setFaceLabel(1, i, "中文名字");
            RtspFaceNative.setFaceLabel(1, i+1, "abcd");
            RtspFaceNative.setFaceLabel(2, i, "中文名字");
            RtspFaceNative.setFaceLabel(2, i+1, "abcd");
        }
        RtspFaceNative.setLocalIP("192.168.1.75");
        mGLView1 = (MyGLSurfaceView) findViewById(R.id.glsurfaceview1);