road_seg_3cls_statistics.h 3.09 KB
#pragma once
#include <string.h>
#include <vector>
#include <opencv2/opencv.hpp>

#include "sy_common.h"
#include "sy_errorinfo.h"

#include <math.h>
#include "../common/logger.hpp"
#include "../ai_platform/macro_definition.h"
#include "road_seg_3cls.h"

#include "acl/acl.h"
#include "acl/ops/acl_dvpp.h"
#include "../util/vpc_util.h"
#include "../util/JpegUtil.h"

using namespace std;
using namespace cv;

class Road3clsSegProcess {

public:
    Road3clsSegProcess();
    ~Road3clsSegProcess();
    /*************************************************************************
    * FUNCTION: Init
    * PURPOSE: 初始化
    * PARAM:
    [in] segparam	参数
    * RETURN:	handle
    * NOTES:
    *************************************************************************/
    int init(int gpu_id, string models_dir);


    /**
     * @brief 道路分割
     *
     * @param handle [in]
     * @param batch_img [in]
     * @param batchsize [in]
     * @param result [in]
     * @return int -1:图像错误; 其他:检测到的个数
     */
    int process_gpu(sy_img * batch_img, vector<DeviceMemory*> vec_segMem, vector<string>& tasklist, 
                                         vector<vector<vector<int>>>& traffic_region, vector<vector<int>>& labels);

    /*************************************************************************
    * FUNCTION: Release
    * PURPOSE: 资源释放
    * PARAM:
    [in] handle		- 处理句柄
    * RETURN:	NULL
    * NOTES:
    *************************************************************************/
    void release();

    cv::Mat mask_to_rgb(cv::Mat img, cv::Mat mask);
    float contourArea(std::vector<cv::Point> contour, cv::Point2f& center);
    void lanes_process(const rs3cls_lane* lanes, int lane_count, std::vector<std::pair<std::vector<cv::Point>, int>>& combined, float scale_w = 1.0, float scale_h = 1.0);
    cv::Mat imshow_lanes(cv::Mat img, const rs3cls_lane* lanes, int lane_count);
    int Mask2LanePoints(const cv::Mat& pred, std::vector<std::vector<cv::Point>>&lanes, std::vector<int>& cats);
    cv::Mat seg_post_process(bool large_resolution, unsigned char *seg_array, std::vector<std::pair<std::vector<cv::Point>, int>> combined, std::vector<std::vector<cv::Point>> &poly_masks, std::vector<int> &region_classes, std::vector<std::vector<cv::Point>> &lanes, std::vector<int> &cats, std::map<double, int> &x_sort);

private:
    int m_devId; 
    aclrtContext m_algorthim_ctx;
    JpegUtil jpegUtil;
    void* m_seg_handle{nullptr};
	float threshold{0.6};
	int m_max_batchsize;
	int SEG_IMG_RES_W = 640;
    int SEG_IMG_RES_H = 360;
    int seg_num_cls = 8;
    int seg_num_seg = 4;
    int seg_min_region_area = 512; //1024 
    float seg_min_lane_score = 0.35; //230625
    uint8_t seg_colors[9][3] = { {0, 0, 0}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {0, 255, 128}, {128, 255, 255}, {255, 128, 255}, {255, 255, 128}, {60, 180, 0}};
    uint8_t lane_colors[9][3] = { {0, 0, 0}, {255, 255, 0}, {255, 0, 255}, {0, 255, 255}, {128, 255, 0}, {255, 128, 0}, {128, 0, 255}, {255, 0, 128}, {0, 128, 255}};
};