Commit 4a273a4acfd70a6dc9029cdab5b08899b2f89a36

Authored by Hu Chunming
1 parent 15756629

添加hcp和hp

algorithm/hcp2/hcp/human_car_parsing.h 0 → 100644
  1 +/*******************************************************************************************
  2 +* Version: human_car_parsing_v0.0.0
  3 +* CopyRight: 中科院自动化研究所模式识别实验室图像视频组
  4 +* UpdateDate: 20190402
  5 +* Content: 人骑车语义分析
  6 +********************************************************************************************/
  7 +
  8 +#ifndef HUMANCARPARSING_H_
  9 +#define HUMANCARPARSING_H_
  10 +
  11 +#ifdef _MSC_VER
  12 +#ifdef HUMANCARPARSING_EXPORTS
  13 +#define HUMANCARPARSING_API __declspec(dllexport)
  14 +#else
  15 +#define HUMANCARPARSING_API __declspec(dllimport)
  16 +#endif
  17 +#else
  18 +#define HUMANCARPARSING_API __attribute__ ((visibility ("default")))
  19 +#endif
  20 +
  21 +#include "sy_common.h"
  22 +
  23 +#ifdef __cplusplus
  24 +extern "C"
  25 +{
  26 +#endif
  27 +
  28 +#ifndef __CLASSIFY_OBJ_RESULT__
  29 +#define __CLASSIFY_OBJ_RESULT__
  30 + typedef struct classify_obj_res //分类结果结构体
  31 + {
  32 + int res_index; //分类结果
  33 + float res_prob; //分类结构体
  34 + classify_obj_res() : res_index(0), res_prob(0) {};
  35 + } classify_obj_res;
  36 +#endif
  37 +
  38 +#ifndef __HCF_FEA_RES__
  39 +#define __HCF_FEA_RES__
  40 +const int HCF_FEATURE_SIZE = 1280;
  41 +#endif
  42 +
  43 +#ifndef __HCP_RESULT__
  44 +#define __HCP_RESULT__
  45 +const int HCP_ATTRI_INDEX_SIZE = 14;
  46 +typedef struct hcp_analysis_result
  47 +{
  48 + classify_obj_res res_objs[HCP_ATTRI_INDEX_SIZE]; //分类结果
  49 + float feature[HCF_FEATURE_SIZE]; //人骑车特征
  50 +} hcp_analysis_result;
  51 +#endif
  52 +
  53 +#ifndef __HCP_PARAM__
  54 +#define __HCP_PARAM__
  55 + typedef struct hcp_param
  56 + {
  57 + int devId; //ָ指定显卡id
  58 + char* modelNames;
  59 + // int mode; //运行模式(DEVICE_GPU / DEVICE_CPU)
  60 + // int gpuid; //ָ指定显卡id
  61 + // int engine; //ָ����������(ENGINE_MCAFFE2 / ENGINE_TENSORRT)
  62 + // int max_batch; //ָ��trt���batch��
  63 + // char* serialize_file;
  64 + // hcp_param() :mode(DEVICE_GPU), gpuid(0) {};
  65 + }hcp_param;
  66 +#endif
  67 +
  68 + /*************************************************************************
  69 + * FUNCTION: hcp_init
  70 + * PURPOSE: 初始化
  71 + * PARAM:
  72 + [out] tools - 句柄
  73 + [in] param - 初始化参数
  74 + * RETURN:
  75 + [out] int - 初始化是否成功(SUCCEEDED表示成功,FAILED表示失败)
  76 + * NOTES:
  77 + *************************************************************************/
  78 + HUMANCARPARSING_API int hcp_init(void ** handle, hcp_param param);
  79 +
  80 + /*************************************************************************
  81 + * FUNCTION: hcp_process
  82 + * PURPOSE: 人骑车属性检测
  83 + * PARAM:
  84 + [in] tools - 句柄
  85 + [in] img_data - 检测图像数据
  86 + [in] result - 检测结果
  87 + * RETURN:
  88 + [out] int - 检测是否成功(SUCCEEDED表示成功,FAILED表示失败)
  89 + * NOTES:
  90 + *************************************************************************/
  91 + // HUMANCARPARSING_API int hcp_process(void * handle, sy_img img_data, hcp_analysis_result * result);
  92 +
  93 + /*************************************************************************
  94 + * FUNCTION: hcp_batch
  95 + * PURPOSE: 人骑车属性检测
  96 + * PARAM:
  97 + [in] tools - 句柄
  98 + [in] img_data_array - 检测图像数据
  99 + [in] batch_size - 检测图像数目
  100 + [in] result - 检测结果
  101 + * RETURN:
  102 + [out] int - 检测是否成功(SUCCEEDED表示成功,FAILED表示失败)
  103 + * NOTES:
  104 + *************************************************************************/
  105 + HUMANCARPARSING_API int hcp_batch(void * handle, sy_img * img_data_array, int batch_size, hcp_analysis_result * result);
  106 +
  107 +
  108 + /*************************************************************************
  109 + * FUNCTION: hcp_release
  110 + * PURPOSE: 资源释放
  111 + * PARAM:
  112 + [in] tools - 处理句柄
  113 + * RETURN: NULL
  114 + * NOTES:
  115 + *************************************************************************/
  116 + HUMANCARPARSING_API void hcp_release(void ** handle);
  117 +
  118 + /*************************************************************************
  119 + * FUNCTION: hcp_get_version
  120 + * PURPOSE:
  121 + * PARAM: NULL
  122 + * RETURN: 版本号
  123 + * NOTES:
  124 + *************************************************************************/
  125 + HUMANCARPARSING_API const char * hcp_get_version();
  126 +
  127 +#ifdef __cplusplus
  128 +};
  129 +#endif
  130 +
  131 +#endif
... ...
algorithm/hcp2/hcp/libhcp.so 0 → 100644
No preview for this file type
algorithm/hcp2/hcp/models/hcp211008_310p.om 0 → 100644
No preview for this file type
algorithm/hcp2/hcp_test/Makefile 0 → 100644
  1 +CC = gcc
  2 +XX = c++
  3 +
  4 +TARGET = start
  5 +
  6 +PROJ_ALL_PATH = $(PWD)/../..
  7 +CUR_PROJ_PATH = $(PWD)
  8 +OPENCV_PATH = $(PROJ_ALL_PATH)/third_party/opencv_4_1
  9 +ACL_PATH = $(ASCEND_AICPU_PATH)/acllib
  10 +
  11 +INCLUDES = -I$(PROJ_ALL_PATH)/common \
  12 + -I$(ACL_PATH)/include \
  13 + -I$(PROJ_ALL_PATH)/common/dvpp \
  14 + -I$(CUR_PROJ_PATH)/../hcp \
  15 + -I$(OPENCV_PATH)/include \
  16 + -I$(OPENCV_PATH)/include/opencv2 \
  17 +
  18 +CFLAGS = -O2 -std=c++11 $(INCLUDES) -DENABLE_DVPP_INTERFACE -D_GLIBCXX_USE_CXX11_ABI=0
  19 +
  20 +local_shared_libs_dirs := \
  21 + $(ACL_PATH)/lib64 \
  22 + $(OPENCV_PATH)/lib \
  23 + $(CUR_PROJ_PATH)/../hcp \
  24 +
  25 +local_shared_libs := \
  26 + ascendcl \
  27 + acl_dvpp \
  28 + opencv_world \
  29 + hcp \
  30 +
  31 +SHARED_LIBRARIES := $(foreach shared_lib, $(local_shared_libs), -l$(shared_lib))
  32 +#SHARED_LIBRARIES_DIRS := $(foreach shared_lib_dir, $(local_shared_libs_dirs), -L$(shared_lib_dir) -Wl,-z,relro,-z,now,-z,noexecstack,-rpath-link,$(shared_lib_dir))
  33 +SHARED_LIBRARIES_DIRS := $(foreach shared_lib_dir, $(local_shared_libs_dirs), -L$(shared_lib_dir) -Wl,-z,relro,-z,now,-z,noexecstack,-rpath,$(shared_lib_dir))
  34 +
  35 +SRCS := $(wildcard $(CUR_PROJ_PATH)/*.cpp)
  36 +SRCS += $(wildcard $(PROJ_ALL_PATH)/common/dvpp/*.cpp)
  37 +
  38 +DIRS := $(notdir $(SRCS))
  39 +OBJS := $(patsubst %cpp, %o, $(DIRS))
  40 +
  41 +all: $(TARGET)
  42 +
  43 +$(TARGET):$(OBJS)
  44 + $(XX) $(CFLAGS) -o $@ $^ $(SHARED_LIBRARIES_DIRS) $(SHARED_LIBRARIES)
  45 +%.o:$(CUR_PROJ_PATH)/%.cpp
  46 + $(XX) $(CFLAGS) -c $<
  47 +%.o:$(PROJ_ALL_PATH)/common/dvpp/%.cpp
  48 + $(XX) $(CFLAGS) -c $<
  49 +
  50 +clean:
  51 + @rm -f $(TARGET)
  52 + @rm -f $(OBJS)
... ...
algorithm/hcp2/hcp_test/test.cpp 0 → 100644
  1 +#include <iostream>
  2 +#include <sstream>
  3 +#include <fstream>
  4 +#include "human_car_parsing.h"
  5 +#include "opencv2/opencv.hpp"
  6 +#include "opencv2/imgcodecs/legacy/constants_c.h"
  7 +#include "opencv2/imgproc/types_c.h"
  8 +#include "time.h"
  9 +#include "sys/time.h"
  10 +#include "sy_errorinfo.h"
  11 +#include "utils.h"
  12 +#include "dvpp_process.h"
  13 +
  14 +using namespace std;
  15 +using namespace cv;
  16 +#include <chrono>
  17 +#include <dirent.h>
  18 +
  19 +
  20 +double msecond() {
  21 + struct timeval tv;
  22 + gettimeofday(&tv, 0);
  23 + return (tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0);
  24 +}
  25 +void getAllNm(std::string pthNm, std::vector<std::string>& fileList)
  26 +{
  27 + DIR *dir;
  28 + struct dirent *ptr;
  29 + dir = opendir(pthNm.c_str()); ///open the dir
  30 + int filenum = 0;
  31 + while((ptr = readdir(dir)) != NULL) ///read the list of this dir
  32 + {
  33 + // char* to string
  34 + std::string curNm = ptr->d_name;
  35 + if(curNm != "." && curNm != "..")
  36 + {
  37 + filenum++;
  38 + fileList.push_back(curNm);
  39 + //printf("file %d name: %s\n", filenum, curNm.c_str());
  40 + }
  41 + }
  42 + closedir(dir);
  43 +}
  44 +
  45 +
  46 +int main() {
  47 + cout << hcp_get_version() << endl;
  48 + const char* img_file_path = "../../../data/hcp/";
  49 + string saveimagepath= "../../../data/result/";
  50 +
  51 + hcp_param param;
  52 + param.modelNames = "../hcp/models/hcp211008_310p.om";
  53 + // param.modelNames = "hcp0629x.om";
  54 + param.devId = 0;
  55 +
  56 + void* handle = nullptr;
  57 + cout << "init start " << endl;
  58 + ACL_CALL(aclInit(nullptr), ACL_SUCCESS, SY_FAILED);
  59 + ACL_CALL(aclrtSetDevice(param.devId), ACL_SUCCESS, SY_FAILED);
  60 + aclrtContext ctx;
  61 + ACL_CALL(aclrtCreateContext(&ctx, param.devId), ACL_SUCCESS, SY_FAILED);
  62 + aclrtStream stream = nullptr;
  63 + ACL_CALL(aclrtCreateStream(&stream), ACL_SUCCESS, SY_FAILED);
  64 + DvppProcess* dvpp = new DvppProcess();
  65 + dvpp->InitResource(stream);
  66 + int ret = hcp_init(&handle, param);
  67 + if (ret == 0) {
  68 + cout << "init success " << endl;
  69 +
  70 + std::vector<std::string> fileList;
  71 +
  72 + getAllNm(img_file_path,fileList);
  73 + if (fileList.empty()) throw std::logic_error("No suitable images were found");
  74 +
  75 + for (auto & file : fileList) {
  76 + string filename = img_file_path + file;
  77 + cout << "img path: " << filename << endl;
  78 +
  79 + const int batchsize = 1;
  80 +
  81 + Mat cvImg = imread(filename.c_str());
  82 + sy_img imgs[batchsize];
  83 +
  84 + ImageData src[batchsize], dvpp_data[batchsize];
  85 + for (int b = 0; b < batchsize; b++) {
  86 + Utils::ReadImageFile(src[b], filename); //将二进制图像读入内存,并读取宽高信息
  87 + ACL_CALL(dvpp->CvtJpegToYuv420sp(dvpp_data[b], src[b]), SY_SUCCESS, SY_FAILED); //解码
  88 + imgs[b].w_ = dvpp_data[b].width;
  89 + imgs[b].h_ = dvpp_data[b].height;
  90 + imgs[b].data_ = dvpp_data[b].data.get();
  91 + }
  92 +
  93 + hcp_analysis_result * results = new hcp_analysis_result[batchsize];
  94 + int ret = hcp_batch(handle, imgs, batchsize, results);
  95 + if (SY_SUCCESS != ret) {
  96 + printf("HumanCarParse process failed!");
  97 + return SY_FAILED;
  98 + }
  99 +
  100 + for(int batchIdx = 0;batchIdx<batchsize;batchIdx++){
  101 + for (int i = 0; i < HCP_ATTRI_INDEX_SIZE; i++) {
  102 + printf("hcp index:%d,confidence:%f\n",results[batchIdx].res_objs[i].res_index,results[batchIdx].res_objs[i].res_prob);
  103 + }
  104 + }
  105 +
  106 + }
  107 + }
  108 +
  109 + hcp_release(&handle);
  110 + aclrtDestroyContext(ctx);
  111 + aclrtResetDevice(param.devId);
  112 + aclFinalize();
  113 +
  114 + return 0;
  115 +}
  116 +
... ...
algorithm/hp2/hp/human_parsing.h 0 → 100644
  1 +/*******************************************************************************************
  2 +* Version: human_parsing_v0.0.0.190402
  3 +* CopyRight: 中科视语(北京)科技有限公司
  4 +* UpdateDate: 20190402
  5 +* Content: 行人分析
  6 +********************************************************************************************/
  7 +
  8 +#ifndef HUMANPARSING_H_
  9 +#define HUMANPARSING_H_
  10 +
  11 +#ifdef _MSC_VER
  12 +#ifdef HUMANPARSING_EXPORTS
  13 +#define HUMANPARSING_API __declspec(dllexport)
  14 +#else
  15 +#define HUMANPARSING_API __declspec(dllimport)
  16 +#endif
  17 +#else
  18 +#define HUMANPARSING_API __attribute__ ((visibility ("default")))
  19 +#endif
  20 +
  21 +#include "sy_common.h"
  22 +
  23 +#ifdef __cplusplus
  24 +extern "C"
  25 +{
  26 +#endif
  27 +
  28 +#ifndef __CLASSIFY_OBJ_RESULT__
  29 +#define __CLASSIFY_OBJ_RESULT__
  30 + typedef struct classify_obj_res //分类结果结构体
  31 + {
  32 + int res_index; //分类结果
  33 + float res_prob; //分类结构体
  34 + classify_obj_res() : res_index(0), res_prob(0) {};
  35 + } classify_obj_res;
  36 +#endif
  37 +
  38 +#ifndef __HF_FEA_RESULT__
  39 +#define __HF_FEA_RESULT__
  40 + const int HF_FEATURE_SIZE = 576;
  41 +#endif
  42 +
  43 +#ifndef __HP_RESULT__
  44 +#define __HP_RESULT__
  45 + const int HP_ATTRI_INDEX_SIZE = 16;
  46 + typedef struct hp_analysis_res
  47 + {
  48 + classify_obj_res res_objs[HP_ATTRI_INDEX_SIZE]; //分类结果
  49 + float feature[HF_FEATURE_SIZE]; //行人特征
  50 + } hp_analysis_res;
  51 +#endif
  52 +
  53 +
  54 +#ifndef __HP_PARAM__
  55 +#define __HP_PARAM__
  56 + typedef struct hp_param
  57 + {
  58 + int devId; //ָ指定显卡id
  59 + char* modelNames; //模型路径
  60 + // int engine; //指定运行引擎(ENGINE_MCAFFE2 / ENGINE_TENSORRT)
  61 + // int max_batch; //指定trt最大batch数
  62 + // char* serialize_file;
  63 + // char* auth_license;
  64 + // hp_param() :mode(DEVICE_GPU), gpuid(0) {};
  65 + }hp_param;
  66 +#endif
  67 +
  68 + /*************************************************************************
  69 + * FUNCTION: hp_init
  70 + * PURPOSE: 初始化
  71 + * PARAM:
  72 + [out] handle - 句柄
  73 + [in] hp_param - 初始化参数
  74 + * RETURN:
  75 + [out] int - 初始化是否成功(SUCCEEDED表示成功,FAILED表示失败)
  76 + * NOTES:
  77 + *************************************************************************/
  78 + HUMANPARSING_API int hp_init(void ** handle, hp_param param);
  79 +
  80 + /*************************************************************************
  81 + * FUNCTION: hp_process
  82 + * PURPOSE: 行人属性检测
  83 + * PARAM:
  84 + [in] tools - 句柄
  85 + [in] img_data - 检测图像数据
  86 + [in] result - 检测结果
  87 + * RETURN:
  88 + [out] int - 检测是否成功(SUCCEED表示成功,FAILED表示失败)
  89 + * NOTES:
  90 + *************************************************************************/
  91 + HUMANPARSING_API int hp_process(void * handle, sy_img img_data, hp_analysis_res * result);
  92 +
  93 + /*************************************************************************
  94 + * FUNCTION: hp_batch
  95 + * PURPOSE: 行人属性检测 batch
  96 + * PARAM:
  97 + [in] tools - 句柄
  98 + [in] img_data_array - 检测图像数据
  99 + [in] batch_size - 检测图像数目
  100 + [in] result - 检测结果
  101 + * RETURN:
  102 + [out] int - 检测是否成功(SUCCEED表示成功,FAILED表示失败)
  103 + * NOTES:
  104 + *************************************************************************/
  105 + HUMANPARSING_API int hp_batch(void * handle, sy_img *img_data_array, int batch_size, hp_analysis_res * result);
  106 +
  107 +
  108 + /*************************************************************************
  109 + * FUNCTION: hp_release
  110 + * PURPOSE: 资源释放
  111 + * PARAM:
  112 + [in] handle - 处理句柄
  113 + * RETURN: NULL
  114 + * NOTES:
  115 + *************************************************************************/
  116 + HUMANPARSING_API void hp_release(void ** handle);
  117 +
  118 + /*************************************************************************
  119 + * FUNCTION: vc_get_version
  120 + * PURPOSE:
  121 + * PARAM: NULL
  122 + * RETURN: 版本号
  123 + * NOTES:
  124 + *************************************************************************/
  125 + HUMANPARSING_API const char * hp_get_version();
  126 +
  127 +#ifdef __cplusplus
  128 +};
  129 +#endif
  130 +#endif
... ...
algorithm/hp2/hp/libhp.so 0 → 100644
No preview for this file type
algorithm/hp2/hp/models/hp220908_310p.om 0 → 100644
No preview for this file type
algorithm/hp2/hp_test/Makefile 0 → 100644
  1 +CC = gcc
  2 +XX = c++
  3 +
  4 +TARGET = start
  5 +
  6 +PROJ_ALL_PATH = $(PWD)/../..
  7 +CUR_PROJ_PATH = $(PWD)
  8 +OPENCV_PATH = $(PROJ_ALL_PATH)/third_party/opencv_4_1
  9 +ACL_PATH = $(ASCEND_AICPU_PATH)/acllib
  10 +
  11 +INCLUDES = -I$(PROJ_ALL_PATH)/common \
  12 + -I$(ACL_PATH)/include \
  13 + -I$(PROJ_ALL_PATH)/common/dvpp \
  14 + -I$(CUR_PROJ_PATH)/../hp \
  15 + -I$(OPENCV_PATH)/include \
  16 + -I$(OPENCV_PATH)/include/opencv2 \
  17 +
  18 +CFLAGS = -O2 -std=c++11 $(INCLUDES) -DENABLE_DVPP_INTERFACE -D_GLIBCXX_USE_CXX11_ABI=0
  19 +
  20 +local_shared_libs_dirs := \
  21 + $(ACL_PATH)/lib64 \
  22 + $(OPENCV_PATH)/lib \
  23 + $(CUR_PROJ_PATH)/../hp \
  24 +
  25 +local_shared_libs := \
  26 + ascendcl \
  27 + acl_dvpp \
  28 + opencv_world \
  29 + hp \
  30 +
  31 +SHARED_LIBRARIES := $(foreach shared_lib, $(local_shared_libs), -l$(shared_lib))
  32 +#SHARED_LIBRARIES_DIRS := $(foreach shared_lib_dir, $(local_shared_libs_dirs), -L$(shared_lib_dir) -Wl,-z,relro,-z,now,-z,noexecstack,-rpath-link,$(shared_lib_dir))
  33 +SHARED_LIBRARIES_DIRS := $(foreach shared_lib_dir, $(local_shared_libs_dirs), -L$(shared_lib_dir) -Wl,-z,relro,-z,now,-z,noexecstack,-rpath,$(shared_lib_dir))
  34 +
  35 +SRCS := $(wildcard $(CUR_PROJ_PATH)/*.cpp)
  36 +SRCS += $(wildcard $(PROJ_ALL_PATH)/common/dvpp/*.cpp)
  37 +
  38 +DIRS := $(notdir $(SRCS))
  39 +OBJS := $(patsubst %cpp, %o, $(DIRS))
  40 +
  41 +all: $(TARGET)
  42 +
  43 +$(TARGET):$(OBJS)
  44 + $(XX) $(CFLAGS) -o $@ $^ $(SHARED_LIBRARIES_DIRS) $(SHARED_LIBRARIES)
  45 +%.o:$(CUR_PROJ_PATH)/%.cpp
  46 + $(XX) $(CFLAGS) -c $<
  47 +%.o:$(PROJ_ALL_PATH)/common/dvpp/%.cpp
  48 + $(XX) $(CFLAGS) -c $<
  49 +
  50 +clean:
  51 + @rm -f $(TARGET)
  52 + @rm -f $(OBJS)
... ...
algorithm/hp2/hp_test/test.cpp 0 → 100644
  1 +#include <iostream>
  2 +#include <sstream>
  3 +#include <fstream>
  4 +#include "human_parsing.h"
  5 +#include "opencv2/opencv.hpp"
  6 +#include "opencv2/imgcodecs/legacy/constants_c.h"
  7 +#include "opencv2/imgproc/types_c.h"
  8 +#include "time.h"
  9 +#include "sys/time.h"
  10 +#include "sy_errorinfo.h"
  11 +#include "utils.h"
  12 +#include "dvpp_process.h"
  13 +
  14 +using namespace std;
  15 +using namespace cv;
  16 +#include <chrono>
  17 +#include <dirent.h>
  18 +
  19 +double msecond() {
  20 + struct timeval tv;
  21 + gettimeofday(&tv, 0);
  22 + return (tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0);
  23 +}
  24 +
  25 +
  26 +void getAllNm(std::string pthNm, std::vector<std::string>& fileList)
  27 +{
  28 + DIR *dir;
  29 + struct dirent *ptr;
  30 + dir = opendir(pthNm.c_str()); ///open the dir
  31 + int filenum = 0;
  32 + while((ptr = readdir(dir)) != NULL) ///read the list of this dir
  33 + {
  34 + // char* to string
  35 + std::string curNm = ptr->d_name;
  36 + if(curNm != "." && curNm != "..")
  37 + {
  38 + filenum++;
  39 + fileList.push_back(curNm);
  40 + //printf("file %d name: %s\n", filenum, curNm.c_str());
  41 + }
  42 + }
  43 + closedir(dir);
  44 +}
  45 +
  46 +int main() {
  47 + cout << hp_get_version() << endl;
  48 + const char* img_file_path = "../../../data/hp/";
  49 + string saveimagepath= "../../../data/result/";
  50 +
  51 + hp_param param;
  52 + param.modelNames = "../hp/models/hp220908_310p.om";
  53 + param.devId = 0;
  54 +
  55 + void* handle = nullptr;
  56 + cout << "init start " << endl;
  57 + ACL_CALL(aclInit(nullptr), ACL_SUCCESS, SY_FAILED);
  58 + ACL_CALL(aclrtSetDevice(param.devId), ACL_SUCCESS, SY_FAILED);
  59 + aclrtContext ctx;
  60 + ACL_CALL(aclrtCreateContext(&ctx, param.devId), ACL_SUCCESS, SY_FAILED);
  61 + aclrtStream stream = nullptr;
  62 + ACL_CALL(aclrtCreateStream(&stream), ACL_SUCCESS, SY_FAILED);
  63 + DvppProcess* dvpp = new DvppProcess();
  64 + dvpp->InitResource(stream);
  65 + int ret = hp_init(&handle, param);
  66 + if (ret == 0) {
  67 + cout << "init success " << endl;
  68 +
  69 + std::vector<std::string> fileList;
  70 +
  71 + getAllNm(img_file_path,fileList);
  72 + if (fileList.empty()) throw std::logic_error("No suitable images were found");
  73 +
  74 + for (auto & file : fileList) {
  75 + string filename = img_file_path + file;
  76 + cout << "img path: " << filename << endl;
  77 +
  78 + const int batchsize = 1;
  79 +
  80 + Mat cvImg = imread(filename.c_str());
  81 + sy_img imgs[batchsize];
  82 +
  83 + ImageData src[batchsize], dvpp_data[batchsize];
  84 + for (int b = 0; b < batchsize; b++) {
  85 + Utils::ReadImageFile(src[b], filename); //将二进制图像读入内存,并读取宽高信息
  86 + ACL_CALL(dvpp->CvtJpegToYuv420sp(dvpp_data[b], src[b]), SY_SUCCESS, SY_FAILED); //解码
  87 + imgs[b].w_ = dvpp_data[b].width;
  88 + imgs[b].h_ = dvpp_data[b].height;
  89 + imgs[b].data_ = dvpp_data[b].data.get();
  90 + }
  91 +
  92 + hp_analysis_res * results = new hp_analysis_res[batchsize];
  93 + int ret = hp_batch(handle, imgs, batchsize, results);
  94 + if (SY_SUCCESS != ret) {
  95 + printf("HumanCarParse process failed!");
  96 + return SY_FAILED;
  97 + }
  98 +
  99 + for(int batchIdx = 0;batchIdx<batchsize;batchIdx++) {
  100 + for (int i = 0; i < HP_ATTRI_INDEX_SIZE; i++) {
  101 + printf("hp index:%d,confidence:%f\n",results[batchIdx].res_objs[i].res_index,results[batchIdx].res_objs[i].res_prob);
  102 + }
  103 + }
  104 +
  105 + if (results) {
  106 + delete[] results;
  107 + results = NULL;
  108 + }
  109 +
  110 + }
  111 + }
  112 +
  113 + hp_release(&handle);
  114 + aclrtDestroyContext(ctx);
  115 + aclrtResetDevice(param.devId);
  116 + aclFinalize();
  117 +
  118 + return 0;
  119 +}
  120 +
... ...
bin/libhcp.so
No preview for this file type
bin/libhp.so 0 → 100644
No preview for this file type
bin/models/hcp/hcp211008_310p.om 0 → 100644
No preview for this file type
bin/models/hp/hp220908_310p.om 0 → 100644
No preview for this file type
build/src/Makefile
... ... @@ -26,9 +26,12 @@ INCLUDES = -I$(PROJ_ALL_PATH)/src/common \
26 26 -I$(OPENCV_PATH)/include/opencv2 \
27 27 -I$(ACL_PATH)/include \
28 28 -I$(SPDLOG_ROOT)/include \
  29 + -I$(CUR_PROJ_PATH)/ai_engine_module \
29 30 -I$(ALGORITHM_PATH)/vehicle_analysis \
30 31 -I$(ALGORITHM_PATH)/vid_clothes2/vid_clothes \
31   - -I$(CUR_PROJ_PATH)/ai_engine_module \
  32 + -I$(ALGORITHM_PATH)/hp2/hp \
  33 + -I$(ALGORITHM_PATH)/hcp2/hcp \
  34 +
32 35  
33 36 # CXXFLAGS = -O0 -std=c++11 $(INCLUDES) -DENABLE_DVPP_INTERFACE -D_GLIBCXX_USE_CXX11_ABI=0
34 37 # CXXFLAGS= -g -O0 -fPIC $(INCLUDES) -lpthread -lrt -lz -fexceptions -std=c++11 -DENABLE_DVPP_INTERFACE -D_GLIBCXX_USE_CXX11_ABI=0 -fvisibility=hidden -Wall -Wno-deprecated -Wdeprecated-declarations -Wl,-Bsymbolic -ldl
... ... @@ -46,6 +49,9 @@ local_shared_libs := \
46 49 spdlog \
47 50 vehicle_analysis \
48 51 vid_clothes \
  52 + hp \
  53 + hcp \
  54 +
49 55  
50 56 SHARED_LIBRARIES := $(foreach shared_lib, $(local_shared_libs), -l$(shared_lib))
51 57 #SHARED_LIBRARIES_DIRS := $(foreach shared_lib_dir, $(local_shared_libs_dirs), -L$(shared_lib_dir) -Wl,-z,relro,-z,now,-z,noexecstack,-rpath-link,$(shared_lib_dir))
... ...
src/PicAnalysis.cpp
... ... @@ -9,12 +9,15 @@ PicAnalysis::PicAnalysis(/* args */)
9 9  
10 10 PicAnalysis::~PicAnalysis()
11 11 {
  12 + release();
12 13 aclFinalize();
13 14 }
14 15  
15 16 int PicAnalysis::init(int dev_id) {
16 17  
17   - int ret = m_vehicle_analysis.init(dev_id, 16);
  18 + int ret = SY_FAILED;
  19 +
  20 + ret = m_vehicle_analysis.init(dev_id, 16);
18 21 if(0 != ret){
19 22 return -1;
20 23 }
... ... @@ -32,8 +35,18 @@ int PicAnalysis::init(int dev_id) {
32 35 return -1;
33 36 }
34 37  
35   - ACL_CALL(aclrtCreateContext(&m_ctx, 0), ACL_ERROR_NONE, SY_FAILED);
36   - ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_ERROR_NONE, SY_FAILED);
  38 + ret = m_human_algorithm.init(dev_id);
  39 + if(0 != ret){
  40 + return -1;
  41 + }
  42 +
  43 + ret = m_human_car_algorithm.init(dev_id);
  44 + if(0 != ret){
  45 + return -1;
  46 + }
  47 +
  48 + ACL_CALL(aclrtCreateContext(&m_ctx, 0), ACL_SUCCESS, SY_FAILED);
  49 + ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_SUCCESS, SY_FAILED);
37 50 ACL_CALL(aclrtCreateStream(&stream), ACL_SUCCESS, SY_FAILED);
38 51 m_dvpp = new DvppProcess();
39 52 m_dvpp->InitResource(stream);
... ... @@ -43,7 +56,7 @@ int PicAnalysis::init(int dev_id) {
43 56  
44 57 int PicAnalysis::analysis_sync(vector<string> vec_file_path){
45 58  
46   - ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_ERROR_NONE, SY_FAILED);
  59 + ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_SUCCESS, SY_FAILED);
47 60  
48 61 const int batch_size = vec_file_path.size();
49 62  
... ... @@ -87,13 +100,19 @@ int PicAnalysis::analysis_sync(vector&lt;string&gt; vec_file_path){
87 100 }
88 101  
89 102 m_clothes_algorithm.detect(vec_img);
  103 +
  104 + m_human_algorithm.detect(vec_img);
  105 +
  106 + m_human_car_algorithm.detect(vec_img);
90 107  
91   -
  108 + LOG_INFO("analysis_sync finished!");
  109 +
92 110 return 0;
93 111 }
94 112  
95 113 int PicAnalysis::release() {
96   - ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_ERROR_NONE, SY_FAILED);
  114 +
  115 + ACL_CALL(aclrtSetCurrentContext(m_ctx), ACL_SUCCESS, SY_FAILED);
97 116  
98 117 delete m_dvpp;
99 118 m_dvpp = nullptr;
... ...
src/PicAnalysis.h
... ... @@ -2,6 +2,8 @@
2 2 #include "./ai_engine_module/VehicleAnalysis.h"
3 3 #include "./ai_engine_module/VehicleHeadTail.h"
4 4 #include "./ai_engine_module/VidClothes.h"
  5 +#include "./ai_engine_module/HumanAnalysis.h"
  6 +#include "./ai_engine_module/HumanCarAnalysis.h"
5 7  
6 8 using namespace std;
7 9  
... ... @@ -27,6 +29,8 @@ private:
27 29 VehicleAnalysis m_vehicle_analysis;
28 30 VehicleHeadTail m_head_tail_algorithm;
29 31 VidClothes m_clothes_algorithm;
  32 + HumanAnalysis m_human_algorithm;
  33 + HumanCarAnalysis m_human_car_algorithm;
30 34 };
31 35  
32 36  
... ...
src/ai_engine_module/HumanAnalysis.cpp 0 → 100644
  1 +#include "HumanAnalysis.h"
  2 +
  3 +HumanAnalysis::HumanAnalysis(/* args */)
  4 +{
  5 +}
  6 +
  7 +HumanAnalysis::~HumanAnalysis()
  8 +{
  9 + release();
  10 +}
  11 +
  12 +int HumanAnalysis::init(int devId){
  13 + ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED);
  14 + ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);
  15 +
  16 + hp_param param;
  17 + param.modelNames = "./models/hp/hp220908_310p.om";
  18 + param.devId = devId;
  19 +
  20 + cout << "hp_init start " << endl;
  21 + int ret = hp_init(&m_handle, param);
  22 + if (ret != 0) {
  23 + return -1;
  24 + }
  25 +
  26 + cout << "hp_init success " << endl;
  27 +
  28 + return SY_SUCCESS;
  29 +}
  30 +
  31 +int HumanAnalysis::detect(vector<sy_img> vec_img){
  32 +
  33 + ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);
  34 +
  35 + const int batchsize = vec_img.size();
  36 + hp_analysis_res * results = new hp_analysis_res[batchsize];
  37 +
  38 + int ret = SY_FAILED;
  39 +
  40 + do
  41 + {
  42 + ret = hp_batch(m_handle, vec_img.data(), batchsize, results);
  43 + if (SY_SUCCESS != ret) {
  44 + printf("vidclothesClassification process failed!");
  45 + break;
  46 + }
  47 +
  48 + for(int batchIdx = 0;batchIdx<batchsize;batchIdx++) {
  49 + for (int i = 0; i < HP_ATTRI_INDEX_SIZE; i++) {
  50 + printf("hp index:%d,confidence:%f\n",results[batchIdx].res_objs[i].res_index,results[batchIdx].res_objs[i].res_prob);
  51 + }
  52 + }
  53 + } while (0);
  54 +
  55 + if (results) {
  56 + delete [] results;
  57 + }
  58 +
  59 + return ret;
  60 +}
  61 +
  62 +int HumanAnalysis::release() {
  63 +
  64 + ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);
  65 +
  66 + if (m_handle) {
  67 + hp_release(&m_handle);
  68 + }
  69 +
  70 + if(ctx){
  71 + aclrtDestroyContext(ctx);
  72 + ctx = nullptr;
  73 + }
  74 +
  75 + return 0;
  76 +}
0 77 \ No newline at end of file
... ...
src/ai_engine_module/HumanAnalysis.h 0 → 100644
  1 +#include "include.h"
  2 +#include "human_parsing.h"
  3 +
  4 +class HumanAnalysis
  5 +{
  6 +public:
  7 + HumanAnalysis(/* args */);
  8 + ~HumanAnalysis();
  9 +
  10 + int init(int devId);
  11 +
  12 + int detect(vector<sy_img> vec_img);
  13 +
  14 +private:
  15 + int release();
  16 +
  17 +private:
  18 + void* m_handle{nullptr};
  19 + aclrtContext ctx{nullptr};
  20 +};
  21 +
... ...
src/ai_engine_module/HumanCarAnalysis.cpp 0 → 100644
  1 +#include "HumanCarAnalysis.h"
  2 +
  3 +HumanCarAnalysis::HumanCarAnalysis(/* args */)
  4 +{
  5 +}
  6 +
  7 +HumanCarAnalysis::~HumanCarAnalysis()
  8 +{
  9 + release();
  10 +}
  11 +
  12 +int HumanCarAnalysis::init(int devId){
  13 + ACL_CALL(aclrtCreateContext(&ctx, devId), SY_SUCCESS, SY_FAILED);
  14 + ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);
  15 +
  16 + hcp_param param;
  17 + param.modelNames = "./models/hcp/hcp211008_310p.om";
  18 + param.devId = devId;
  19 +
  20 + cout << "hcp_init start " << endl;
  21 + int ret = hcp_init(&m_handle, param);
  22 + if (ret != 0) {
  23 + return -1;
  24 + }
  25 +
  26 + cout << "hcp_init success " << endl;
  27 +
  28 + return SY_SUCCESS;
  29 +}
  30 +
  31 +int HumanCarAnalysis::detect(vector<sy_img> vec_img){
  32 +
  33 + ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);
  34 +
  35 + const int batchsize = vec_img.size();
  36 + hcp_analysis_result * results = new hcp_analysis_result[batchsize];
  37 +
  38 + int ret = SY_FAILED;
  39 +
  40 + do
  41 + {
  42 + ret = hcp_batch(m_handle, vec_img.data(), batchsize, results);
  43 + if (SY_SUCCESS != ret) {
  44 + printf("vidclothesClassification process failed!");
  45 + break;
  46 + }
  47 +
  48 + for(int batchIdx = 0;batchIdx<batchsize;batchIdx++){
  49 + for (int i = 0; i < HCP_ATTRI_INDEX_SIZE; i++) {
  50 + printf("hcp index:%d,confidence:%f\n",results[batchIdx].res_objs[i].res_index,results[batchIdx].res_objs[i].res_prob);
  51 + }
  52 + }
  53 + } while (0);
  54 +
  55 + if (results) {
  56 + delete [] results;
  57 + }
  58 +
  59 + return ret;
  60 +}
  61 +
  62 +int HumanCarAnalysis::release() {
  63 +
  64 + ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);
  65 +
  66 + if (m_handle) {
  67 + hcp_release(&m_handle);
  68 + }
  69 +
  70 + if(ctx){
  71 + aclrtDestroyContext(ctx);
  72 + ctx = nullptr;
  73 + }
  74 +
  75 + return SY_SUCCESS;
  76 +}
0 77 \ No newline at end of file
... ...
src/ai_engine_module/HumanCarAnalysis.h 0 → 100644
  1 +#include "include.h"
  2 +#include "human_car_parsing.h"
  3 +
  4 +class HumanCarAnalysis
  5 +{
  6 +public:
  7 + HumanCarAnalysis(/* args */);
  8 + ~HumanCarAnalysis();
  9 +
  10 + int init(int devId);
  11 +
  12 + int detect(vector<sy_img> vec_img);
  13 +
  14 +private:
  15 + int release();
  16 +
  17 +private:
  18 + void* m_handle{nullptr};
  19 + aclrtContext ctx{nullptr};
  20 +};
  21 +
... ...
src/ai_engine_module/VidClothes.cpp
... ... @@ -15,9 +15,9 @@ int VidClothes::init(int devId){
15 15 vidclothes_param param;
16 16 param.modelNames = "./models/vid_clothes/vidClothes0325_310P.om";
17 17 param.thresld = 0.0;
18   - param.devId = 0;
  18 + param.devId = devId;
19 19  
20   - cout << "vidclothes_init start " << endl;
  20 + cout << "vidclothes_init start " << endl;
21 21 int ret = vidclothes_init(&m_handle, param);
22 22 if (ret != 0) {
23 23 return -1;
... ... @@ -57,13 +57,18 @@ int VidClothes::detect(vector&lt;sy_img&gt; vec_img){
57 57 return ret;
58 58 }
59 59  
60   -void VidClothes::release() {
61   - if(ctx){
62   - aclrtSetCurrentContext(ctx);
63   - aclrtDestroyContext(ctx);
64   - }
  60 +int VidClothes::release() {
  61 +
  62 + ACL_CALL(aclrtSetCurrentContext(ctx), SY_SUCCESS, SY_FAILED);
65 63  
66 64 if (m_handle) {
67 65 vidclothes_release(&m_handle);
68 66 }
  67 +
  68 + if(ctx){
  69 + aclrtDestroyContext(ctx);
  70 + ctx = nullptr;
  71 + }
  72 +
  73 + return SY_SUCCESS;
69 74 }
70 75 \ No newline at end of file
... ...
src/ai_engine_module/VidClothes.h
... ... @@ -3,8 +3,6 @@
3 3  
4 4 class VidClothes
5 5 {
6   -private:
7   - /* data */
8 6 public:
9 7 VidClothes(/* args */);
10 8 ~VidClothes();
... ... @@ -14,7 +12,7 @@ public:
14 12 int detect(vector<sy_img> vec_img);
15 13  
16 14 private:
17   - void release();
  15 + int release();
18 16  
19 17 private:
20 18 void* m_handle{nullptr};
... ...
src/main.cpp
... ... @@ -9,12 +9,12 @@ int main() {
9 9 vector<string> vec_path;
10 10 for (size_t i = 0; i < 10; i++)
11 11 {
12   - vec_path.push_back("./test_head_tail.jpg");
  12 + vec_path.push_back("./test_hv.jpg");
13 13 }
14 14  
15 15 pic_analysis.analysis_sync(vec_path);
16 16  
17   - pic_analysis.release();
  17 + while (getchar() != 'q');
18 18  
19 19 return 0;
20 20 }
21 21 \ No newline at end of file
... ...