motocycle_hs_process.h 3.05 KB
#pragma once
#include <deque>
#include <map>
#include <vector>
#include <memory>
#include "../util/vpc_util.h"
#include "../ai_platform/task_param_manager.h"
#include "../ai_platform/macro_definition.h"
#include "ai_engine_header.h"
#include "hs_det_motor.h"
#include "acl/acl.h"
#include "acl/ops/acl_dvpp.h"

#define MAX_BATCH 16
#define IMAGE_CROP_EXPAND_RATIO 0
#define MAX_OBJ_BOX_COUNT 100

namespace ai_engine_module
{
    namespace motocycle_hs_process
    {
        // typedef long id_t;
        using id_t = obj_key_t;
        using task_id_t = std::string;
        using algor_param_type = algor_config_param_manned_incident*;

        enum class label_t {
            PLACEHOLDER = -1,
            helmet_major = 0,   //戴头盔_主要车
            nohelmet_major = 1, //不带头盔_主要车
            helmet_minor = 2,   //戴头盔_次要车
            nohelmet_minor = 3, //不带头盔_次要车
        };

        typedef struct input_data_wrap_t
        {
            id_t id;
            long objId;
            std::string taskId;
            box_t box;
        } input_data_wrap_t;


        typedef struct mn_frame_t
        {
            uint m_frame;
            uint n_frame;

            // explicit
            mn_frame_t(uint m = 0, uint n = 0)
                : m_frame(m)
                , n_frame(n)
            {}

            void reset()
            {
                m_frame = 0;
                n_frame = 0;
            }

        } mn_frame_t;


        typedef struct results_data_t 
        {
            box_t box;
            acldvppPicDesc* origin_img_desc{nullptr};
            acldvppPicDesc* roi_img_desc{nullptr};
            id_t id;
            long objId;
            std::string taskId;
            algorithm_type_t algor_type;
        } results_data_t;

        class MotorHsProcess
        {
            /**
             * @brief
             *  1. move able
             */
        public:
            MotorHsProcess();

            ~MotorHsProcess();

            bool check_initied();
            bool init(int gpu_id, string models_dir);
            bool update_mstreams(const std::vector<task_id_t>& taskIds, vector<DeviceMemory*> vec_det_input_images, const std::vector<onelevel_det_result> &det_results); 
            std::shared_ptr<results_data_t> get_result_by_objectid(const id_t& id, bool do_erase = true);

            void force_release_result(const task_id_t& task_id);

            MotorHsProcess(const MotorHsProcess&) = delete;
            MotorHsProcess& operator=(const MotorHsProcess&) = delete;

        private:
            static algorithm_type_t algor_type_;
            int m_devId; 
            aclrtContext m_algorthim_ctx;

            bool init_;
            void* tools_;
            task_param_manager* task_param_manager_;
            std::map<id_t, mn_frame_t> id_to_mn_;
            std::map<id_t, results_data_t> id_to_result_;
        };
    }  // namespace motocycle_hs_process
} // namespace ai_engine_module