Newer
Older
lynxi-plugin / src / ipe / ipeParam.h
/**
 *@file ipeParam.h
 *@author SDK
 *@version v1.0
 *@date 2021-10-22
 *@par Copyright:
 *© 2018 北京灵汐科技有限公司 版权所有。\n
 * 注意:以下内容均为北京灵汐科技有限公司原创,未经本公司允许,不得转载,否则将视为侵权;对于不遵守此声明或者其他违法使用以下内容者,本公司依法保留追究权。\n
 *© 2018 Lynxi Technologies Co., Ltd. All rights reserved. \n
 * NOTICE: All information contained here is, and remains the property of Lynxi. This file can not be copied or
 *distributed without the permission of Lynxi Technologies Co., Ltd.
 *@brief This file describes the base functions in samples
 */

#ifndef SDK_POST_IPE_H
#define SDK_POST_IPE_H

#define CHECK_ERR(err)                                                                             \
    do {                                                                                           \
        auto _err = (err);                                                                         \
        if (_err != 0) {                                                                           \
            std::cout << __FILE__ << ":" << __LINE__ << " " << _err << std::endl;                  \
            quick_exit(-1);                                                                        \
        }                                                                                          \
    } while (0)

#include <lyn_api.h>
#include <iostream>
    
class IpeParamBase
{
  protected:
    // 输出宽高
    int m_iOutputWidth = 0;
    int m_iOutputHeight = 0;

    // 输入图片信息
    int m_iImgWidth = 0;
    int m_iImgHeight = 0;
    lynPixelFormat_t m_format = LYN_PIX_FMT_NONE;

  public:
    // ipe输入信息
    lynIpePicDesc_t m_oPicDescIn;
    // ipe输出信息
    lynIpePicDesc_t m_oPicDescOut;
    // ipe配置信息
    lynIpeConfigDesc_t m_oConfigDesc;
    lynIpeAffineHandle_t m_affineHandle;
  public:
    IpeParamBase(int iOutputWidth, int iOutputHeight) : m_iOutputWidth(iOutputWidth), m_iOutputHeight(iOutputHeight)
    {
        // 创建ipe相关结构体
        CHECK_ERR(lynIpeCreatePicDesc(&m_oPicDescIn));
        CHECK_ERR(lynIpeCreatePicDesc(&m_oPicDescOut));
        CHECK_ERR(lynIpeCreateConfigDesc(&m_oConfigDesc));
    }

    ~IpeParamBase()
    {
        // 释放ipe相关结构体
        CHECK_ERR(lynIpeDestroyPicDesc(m_oPicDescIn));
        CHECK_ERR(lynIpeDestroyPicDesc(m_oPicDescOut));
        CHECK_ERR(lynIpeDestroyConfigDesc(m_oConfigDesc));
    }

    void Init()
    {

    }

    void UnInit()
    {

    }

    // 设置输入图片的信息(接口分开为了同一类型的图片该方法可只调一次)
    virtual void SetImgInfo(int32_t width, int32_t height, lynPixelFormat_t format)
    {
        m_iImgWidth = width;
        m_iImgHeight = height;
        m_format = format;
    }

    // IPE处理虚函数
    virtual void CalcParam(void *inputData, void *outputData) = 0;
};


// Yolov3 Ipe参数
class IpeParam: public IpeParamBase
{

  public:
    IpeParam(int iOutputWidth, int iOutputHeight) : IpeParamBase(iOutputWidth, iOutputHeight)
    {
        CHECK_ERR(lynIpeOpenAffineHandle(&m_affineHandle));
    }

    ~IpeParam()
    {
        CHECK_ERR(lynIpeCloseAffineHandle(m_affineHandle));
    }


    // 计算IPE处理参数
    virtual void CalcParam(void *inputData, void *outputData)
    {
        // 初始化ipe相关结构体
        CHECK_ERR(lynIpeResetPicDesc(m_oPicDescIn));
        CHECK_ERR(lynIpeResetPicDesc(m_oPicDescOut));
        CHECK_ERR(lynIpeResetConfigDesc(m_oConfigDesc));

        // 设置ipe的输入输出参数
        CHECK_ERR(lynIpeSetInputPicDesc(m_oPicDescIn, inputData, m_iImgWidth, m_iImgHeight, m_format));
        CHECK_ERR(lynIpeSetOutputPicData(m_oPicDescOut, outputData));

        // 设置ipe处理参数
        CHECK_ERR(lynIpeSetResizeConfig(m_oConfigDesc, m_iOutputWidth, m_iOutputHeight));

        CHECK_ERR(lynIpeCalOutputPicDesc(m_oPicDescOut, m_oPicDescIn, m_oConfigDesc, 0));
        CHECK_ERR(lynIpeProcess(m_oPicDescIn, m_oPicDescOut, m_oConfigDesc));
    }

    void CalcAffineParam(void *inputData, void *outputData, float (*matrix)[3])
    {
        // 初始化ipe相关结构体
        CHECK_ERR(lynIpeResetPicDesc(m_oPicDescIn));
        CHECK_ERR(lynIpeResetPicDesc(m_oPicDescOut));
        CHECK_ERR(lynIpeResetConfigDesc(m_oConfigDesc));

        // 设置ipe的输入输出参数
        CHECK_ERR(lynIpeSetInputPicDesc(m_oPicDescIn, inputData, m_iImgWidth, m_iImgHeight, m_format));
        CHECK_ERR(lynIpeSetOutputPicDesc(m_oPicDescOut, outputData,  m_iOutputWidth, m_iOutputHeight, m_format));
        CHECK_ERR(lynIpeSetAffineConfigV2(m_oConfigDesc, matrix, 0, 255, 0, m_affineHandle));
        CHECK_ERR(lynIpeProcess(m_oPicDescIn, m_oPicDescOut, m_oConfigDesc));
    }

};

#endif // SDK_POST_IPE_H