You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

532 lines
30 KiB
C++

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#ifndef LPBENGINE_H
#define LPBENGINE_H
#include "lpbdefine.h"
enum LpAdapterType
{
ADAPTER_NULL = 0,
ADAPTER_CAMERA,
ADAPTER_SERIALPORT,
ADAPTER_FILE,
};
enum ItemBEType
{
RECTANGLE = 0,
CIRCLE,
ELLIPSE,
POLY
};
enum ItemPos
{
EXTERIOR = 0,
INTERIOR,
};
//<! 静态
#define LP_MAX_ALGO_PARAM_NUM 33
static QString AlgoParamName[LP_MAX_ALGO_PARAM_NUM] = {
"INT",
"BOOLEAN",
"STRING",
"DOUBLE",
"IMAGE",
"POINT",
"POINTF",
"RECT",
"RECTF",
"ROI",
"MAT",
"LIST_INT",
"LIST_BOOLEAN",
"LIST_STRING",
"LIST_DOUBLE",
"USER"
"LINE",
"LINEF",
"CIRCLE",
"CIRCLEF",
"POLYGON",
"POLYGONF",
"TRANSFORM",
"WORD",
"VARIANT",
"MAP_VARIANT",
"LIST_POLYGON",
"LIST_POLYGONF",
"LIST_CIRCLE",
"LIST_CIRCLEF",
"LIST_POINT",
"LIST_POINTF",
"LIST_LINE",
"LIST_LINEF",
};
enum AlgoParamType
{
LP_INT = 0,
LP_BOOLEAN,
LP_STRING,
LP_DOUBLE,
LP_IMAGE,
LP_POINT,
LP_POINTF,
LP_RECT,
LP_RECTF,
LP_ROI,
LP_MAT,
LP_LIST_INT,
LP_LIST_BOOLEAN,
LP_LIST_STRING,
LP_LIST_DOUBLE,
LP_USER,
LP_LINE,
LP_LINEF,
LP_CIRCLE,
LP_CIRCLEF,
LP_POLYGON,
LP_POLYGONF,
LP_TRANSFORM,
LP_WORD,
LP_VARIANT,
LP_MAP_VARIANT,
LP_LIST_POLYGON,
LP_LIST_POLYGONF,
LP_LIST_CIRCLE,
LP_LIST_CIRCLEF,
LP_LIST_POINT,
LP_LIST_POINTF,
LP_LIST_LINE,
LP_LIST_LINEF,
};
enum SolutionStateFlag {
SolutionIsRun = 0x1,
SolutionIsModify = 0x2,
SolutionIsReset = 0x4,
};
enum SolutionType {
LP_CUSTOM = 0,
LP_COMMON,
LP_EXTRA,
};
enum ParamDir {
LP_PARAM_INPUT = 0,
LP_PARAM_OUTPUT,
};
typedef struct tagDetectorDevice
{
int nID;
QString strName;
}LP_DETECTOR_DEVICE, *PLP_DETECTOR_DEVICE;
typedef struct tagAlgorithmParamDesc
{
QString strName;
AlgoParamType type;
ParamDir dir;
QVariant InitVal;
}LP_ALGORITHM_PARAM_DESC, *PLP_ALGORITHM_PARAM_DESC;
typedef struct tagAlgorithmParam
{
int nID;
int nTaskID;
int nSrcAlgoID;
int nSrcParamID;
QString strName;
AlgoParamType type;
QVariant value;
QString strDescription;
bool bIsSave;
bool bIsLock;
bool bIsShow{true};
QVariantMap vProperty;
tagAlgorithmParam(QString strName = "",
AlgoParamType type = LP_INT,
QVariant value = NULL,
QString strDescription = "",
int nTaskID = LP_DETECTOR_INVALID_ID,
int nSrcAlgoID = LP_DETECTOR_INVALID_ID,
int nSrcParamID = LP_DETECTOR_INVALID_ID,
bool bIsSave = false,
bool bIsLock = false,
bool bIsShow = true,
QVariantMap vProperty = QVariantMap()
)
{
this->strName = strName;
this->type = type;
this->value = value;
this->strDescription = strDescription;
this->nTaskID = nTaskID;
this->nSrcAlgoID = nSrcAlgoID;
this->nSrcParamID = nSrcParamID;
this->bIsSave = bIsSave;
this->bIsLock = bIsLock;
this->bIsShow = bIsShow;
this->vProperty = vProperty;
};
void operator=(const tagAlgorithmParam& other)
{
nID = other.nID;
nTaskID = other.nTaskID;
nSrcAlgoID = other.nSrcAlgoID;
nSrcParamID = other.nSrcParamID;
strName = other.strName;
type = other.type;
value = other.value;
strDescription = other.strDescription;
bIsSave = other.bIsSave;
bIsLock = other.bIsLock;
vProperty = other.vProperty;
}
}LP_ALGORITHM_PARAM, *PLP_ALGORITHM_PARAM;
typedef QPair <int, QList<float>> Feature_List;
typedef QList<Feature_List> Item_List;
typedef QList<Item_List> Record_List;
typedef struct tagROIRecordItem
{
int nID;
ItemPos posType;
Feature_List featureData;
}LP_DETECTOR_ROI_RECORD_ITEM, *PLP_DETECTOR_ROI_RECORD_ITEM;
typedef struct tagROIRecord
{
int nID;
QString strName;
}LP_DETECTOR_ROI_RECORD, *PLP_DETECTOR_ROI_RECORD;
typedef struct tagROIData
{
Record_List records;
cv::Mat img;
}LP_DETECTOR_ROI_DATA, *PLP_DETECTOR_ROI_DATA;
typedef struct tagImageData
{
int nType;
QString strName;
cv::Mat img;
}LP_DETECTOR_IMAGE_CACHE_DATA, *PLP_DETECTOR_IMAGE_CACHE_DATA;
typedef struct tagTaskOutParam
{
QString name;
AlgoParamType type;
QVariant value;
}LP_DETECTOR_TASK_OUT_PARAM, *PLP_DETECTOR_TASK_OUT_PARAM;
Q_DECLARE_METATYPE(cv::Mat)
Q_DECLARE_METATYPE(LP_DETECTOR_ROI_DATA)
Q_DECLARE_METATYPE(LP_DETECTOR_IMAGE_CACHE_DATA)
Q_DECLARE_METATYPE(LP_DETECTOR_TASK_OUT_PARAM)
typedef struct tagDetectorROI
{
int nID;
QString strName;
QString strDescription;
int rgb;
}LP_DETECTOR_ROI, *PLP_DETECTOR_ROI;
typedef struct tagDetectorAlgorithm
{
int nID;//算法ID
QString strName;//算法名称
QString strDescription;//描述
QString strPath;//算法路径 即算法模块名字
QString strLibName;
QString strFuncName;
int nRoiID;
}LP_DETECTOR_ALGORITHM, *PLP_DETECTOR_ALGORITHM;
typedef struct tagDetectorTask
{
int nID;
int nCameraID;
int nGroupParamID;
quint64 timeStamp;
QString strName;
QString strDescription;
QString strImageName;
QString strDirPath;
cv::Mat templateImg;//模板图片 标定图
cv::Mat detectImg;//实时检测图
bool bIsRun;
QVariant property;
}LP_DETECTOR_TASK, *PLP_DETECTOR_TASK;
typedef struct tagDetectorSolution
{
int nID;
int nType;
QString strName;
QString strDescription;
}LP_DETECTOR_SOLUTION, *PLP_DETECTOR_SOLUTION;
typedef void(__stdcall *NewImageHandler)(void * callBackOwner, QImage& img, int nDeviceID);
typedef bool(*callFunc)(class IDetectorTask *lpRegion, class IDetectorAlgorithm* lpAlgorithm);
typedef QList <LP_ALGORITHM_PARAM_DESC> ParamDescList;
class IAlgorithmLib
{
public:
IAlgorithmLib(){}
virtual ~IAlgorithmLib(){}
virtual bool InitAlgo(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgorithm) = 0;
virtual void LoadUserParamValue(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgorithm, QString& strParamName, QVariant& value) = 0;
virtual void SaveUserParamValue(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgorithm, QString& strParamName) = 0;
virtual bool RegisterFunc(const QString& strName, callFunc func) = 0;
virtual bool DefFuncParam(const QString& strName, LP_ALGORITHM_PARAM_DESC descParam) = 0;
virtual bool CallFunc(const QString& strName, IDetectorTask *lpRegion, IDetectorAlgorithm* lpAlgorithm) = 0;
virtual QStringList ListFunc() = 0;
virtual QList < LP_ALGORITHM_PARAM_DESC > ListParamDesc(const QString& strFuncName) = 0;
virtual bool HandleEvent(IDetectorTask *lpTask, IDetectorAlgorithm* lpAlgorithm, QString strParaName = "", int event = -1) = 0;
};
class IAlgorithmLibMgr
{
public:
IAlgorithmLibMgr(){}
virtual ~IAlgorithmLibMgr(){}
virtual bool AddAlgorithmLib(const QString& strName, const QString& strPath) = 0;
virtual void DeleteAlgorithmLib(const QString& strName) = 0;
virtual IAlgorithmLib* GetAlgorithmLib(const QString& strName) = 0;
virtual QStringList ListAlgoLib() = 0;
};
class IDetectorRecord
{
public:
IDetectorRecord(){}
virtual ~IDetectorRecord(){}
virtual PLP_DETECTOR_ROI_RECORD_ITEM AddItem(const PLP_DETECTOR_ROI_RECORD_ITEM pItem, bool bRet = true) = 0;
virtual bool DeleteItem(int nItemID) = 0;
virtual PLP_DETECTOR_ROI_RECORD_ITEM GetItem(int nItemID) = 0;
virtual int EnumItem(LP_DETECTOR_ROI_RECORD_ITEM** lppItem, int nCount) = 0;
virtual bool SetRecordInfo(const PLP_DETECTOR_ROI_RECORD pRecord) = 0;
virtual PLP_DETECTOR_ROI_RECORD GetRecordInfo() = 0;
virtual int GetID() const = 0;
virtual void Release() = 0;
virtual PLP_DETECTOR_ROI_RECORD_ITEM GetExteriorItem() = 0;
virtual PLP_DETECTOR_ROI_RECORD_ITEM GetInteriorItem() = 0;
};
class IDetectorROI
{
public:
IDetectorROI(){}
virtual ~IDetectorROI(){}
virtual IDetectorRecord* AddRecord(const PLP_DETECTOR_ROI_RECORD pRecord, bool bRet = true) = 0;
virtual bool DeleteRecord(int nRecordID) = 0;
virtual IDetectorRecord* GetRecord(int nRecordID) = 0;
virtual int EnumRecord(IDetectorRecord** lppRecord, int nCount) = 0;
virtual bool SetROIInfo(const PLP_DETECTOR_ROI pROI) = 0;
virtual PLP_DETECTOR_ROI GetROIInfo() = 0;
virtual int GetID() const = 0;
virtual void CleanUp() = 0;
virtual void Release() = 0;
};
class IDetectorAlgorithm
{
public:
IDetectorAlgorithm(){}
virtual ~IDetectorAlgorithm(){}
virtual bool SetAlgorithmInfo(const PLP_DETECTOR_ALGORITHM pAlgorithmInfo) = 0;
virtual PLP_DETECTOR_ALGORITHM GetAlgorithmInfo() = 0;
virtual PLP_ALGORITHM_PARAM AddParam(const PLP_ALGORITHM_PARAM pParam, bool bRet = true) = 0;
virtual bool DeleteParam(int nParamID) = 0;
virtual PLP_ALGORITHM_PARAM GetParam(int nParamID) = 0;
virtual PLP_ALGORITHM_PARAM GetParamByName(QString strName) = 0;
virtual int GetParamCount() = 0;
virtual QMap<QString, PLP_ALGORITHM_PARAM> GetAllParams() = 0;
virtual PLP_ALGORITHM_PARAM AddOutParam(const PLP_ALGORITHM_PARAM pOutParam, bool bRet = true) = 0;
virtual bool DeleteOutParam(int nOutParamID) = 0;
virtual PLP_ALGORITHM_PARAM GetOutParam(int nOutParamID) = 0;
virtual PLP_ALGORITHM_PARAM GetOutParamByName(QString strName) = 0;
virtual int GetOutParamCount() = 0;
virtual QMap<QString, PLP_ALGORITHM_PARAM> GetAllOutParams() = 0;
virtual int GetID() const = 0;
virtual int GetParamBaseID() const = 0;
virtual int GetOutParamBaseID() const = 0;
virtual void Release() = 0;
virtual bool Load(QString dllPath) = 0;
virtual bool InitAlgo() = 0;
virtual bool Exec() = 0;
virtual QVariant GetParamValue(QString strKey, AlgoParamType type) = 0;
virtual QVariant GetOutParamValue(QString strKey, AlgoParamType type) = 0;
virtual bool SetOutParamValue(QString strKey, QVariant value) = 0;
virtual bool ImportParam(QJsonArray paramArray) = 0;
virtual QByteArray ExportParam() = 0;
virtual bool ImportOutParam(QJsonArray outParamArray) = 0;
virtual QByteArray ExportOutParam() = 0;
virtual bool SwapParamOrder(int nID1, int nID2) = 0;
virtual bool InsertParamOrder(int nID, int nIndex) = 0;
virtual bool UpdateParamValue(int nParamID, QVariant& value) = 0;
virtual bool UpdateParamValueByName(QString strName, QVariant& value) = 0;
virtual QList<int> UpdateRelyOnAlgo() = 0; //更新算法输出参数value到其关联的所有其他算法输入参数中
virtual QList<int> GetRelyOnAlgo() = 0; //获取依赖其的算法列表
virtual QPolygonF GetRoiInfo() = 0;
virtual void SetEnabled(bool bEnable) = 0;
virtual bool IsEnabled() const = 0;
virtual bool Copy(IDetectorAlgorithm* pSrcAlgo, bool bRet = true) = 0;
virtual bool ExecOnce() = 0;
virtual bool HandleEvent(QString strParamName = "", int event = -1) = 0;
virtual double ExecTime() const = 0;
};
class IDetectorSolution;
class IDetectorTask
{
public:
IDetectorTask(){}
virtual ~IDetectorTask(){}
virtual IDetectorROI* AddROI(const PLP_DETECTOR_ROI pROI, bool bRet = true) = 0;
virtual bool DeleteROI(int nROIID) = 0;
virtual IDetectorROI* GetROI(int nROIID) = 0;
virtual int EnumROI(IDetectorROI** lppROI, int nCount) = 0;
virtual IDetectorAlgorithm* AddAlgorithm(const PLP_DETECTOR_ALGORITHM pAlgorithm, bool bRet = true) = 0;
virtual bool DeleteAlgorithm(int nAlgorithmID) = 0;
virtual IDetectorAlgorithm* GetAlgorithm(int nAlgorithmID) = 0;
virtual int GetAlgorithmCount() = 0;
virtual QMap<int, IDetectorAlgorithm*> GetAllAlgorithms() = 0;
virtual bool SetTaskInfo(const PLP_DETECTOR_TASK pTask) = 0;
virtual PLP_DETECTOR_TASK GetTaskInfo() = 0;
virtual int GetID() const = 0;
virtual int GetAlgoBaseID() const = 0;
virtual void Release() = 0;
virtual bool SetRunAlgo(int nAlgoID) = 0;
virtual IDetectorAlgorithm* GetRunAlgo() = 0;
virtual IDetectorSolution* GetParentSolution() = 0;
virtual bool Copy(IDetectorTask* pSrcTask, bool bRet = true) = 0;
virtual QVariant GetSystemInfoValue(const QString &key) = 0;
virtual bool PushImage(PLP_DETECTOR_IMAGE_CACHE_DATA pImageData) = 0;
virtual bool SaveFile(const QString& strPath) = 0;
virtual bool LoadFile(const QString& strPath) = 0;
virtual bool RemoveFile() = 0;
virtual bool AppendOtherFile(QString strpath) = 0;
virtual bool Exec() = 0;
virtual bool IsRunning() const = 0;
virtual double ExecTime() const = 0;
//同步框架IVariantMapToUI的数据到task中如map数据格式更改需要同时更新该接口实现
virtual bool SyncMapResult(const QVariantMap& vMap) = 0;
virtual QString GetPath() = 0;
virtual QString GetTaskName() = 0;
};
class IDetectorSolution
{
public:
IDetectorSolution(){}
virtual ~IDetectorSolution(){}
virtual bool AddTaskByTemplate(QString strName) = 0;
virtual IDetectorTask* AddTask(const PLP_DETECTOR_TASK pTask) = 0;
virtual bool DeleteTask(QString strTaskName) = 0;
virtual IDetectorTask* GetTaskByName(QString strName) = 0;
virtual QStringList GetAllTaskNames() = 0;
virtual QMap<QString, IDetectorTask*> GetAllTasks() = 0;
virtual bool SetSolutionInfo(const PLP_DETECTOR_SOLUTION pProduct) = 0;
virtual PLP_DETECTOR_SOLUTION GetSolutionInfo() = 0;
virtual QString GetSolutionName() = 0;
virtual int GetID() const = 0;
virtual void Release() = 0;
virtual IDetectorSolution* Copy() = 0;
virtual bool GetRunState() = 0;
virtual void SetRunState(bool bRun) = 0;
virtual bool GetModifyFlag() = 0;
virtual void SetModifyFlag(bool bModify) = 0;
virtual bool SetRunTask(QString strTaskName) = 0;
virtual bool Copy(IDetectorSolution* pSrcSolution, bool bRet = true) = 0;
virtual IDetectorTask* AddAndCopyTask(IDetectorTask* pSrcTask, LP_DETECTOR_TASK tTaskInfo) = 0;
virtual int GetTaskBaseID() const = 0;
virtual bool SaveTaskByName(QString strName) = 0;
virtual bool SaveFileEx(const QString& strPath) = 0;
virtual bool SaveFileEx(const QString& strPath, QStringList strTaskNames) = 0;
virtual bool LoadFileEx(const QString& strPath) = 0;
virtual void SaveUserParamValue() = 0;
virtual void LoadUserParamValue() = 0;
virtual void ClearUserParamValue() = 0;
};
class IDetectorSolutionMgr
{
public:
IDetectorSolutionMgr(){}
virtual ~IDetectorSolutionMgr(){}
virtual IDetectorSolution* AddSolution(const PLP_DETECTOR_SOLUTION pSolution) = 0;
virtual bool DeleteSolutionByID(QString strName) = 0;
virtual IDetectorSolution* GetSolutionByID(QString strName) = 0;
virtual int GetSolutionCount() = 0;
virtual QMap<QString, IDetectorSolution*> GetAllSolutions() = 0;
virtual bool Save() = 0;
virtual bool SaveByNames(QStringList strNames) = 0;
virtual bool Load() = 0;
virtual bool ReLoad() = 0;
virtual bool SetRunSolution(QString strName) = 0;
virtual IDetectorSolution* GetRunSolution() = 0;
virtual IDetectorSolution* AddAndCopySolution(IDetectorSolution* pSrcSolution) = 0;
};
typedef std::function<void(QVariantMap)> AlgResultCallBack;
class IDetectorEngine
{
public:
IDetectorEngine() {};
virtual ~IDetectorEngine() {};
virtual bool Initialize() = 0;
virtual IAlgorithmLibMgr* getAlgorithmLibMgr() = 0;
virtual IDetectorSolutionMgr* getSolutionMgr() = 0;
virtual bool detect(cv::Mat srcImg, QString modeName, AlgResultCallBack func) = 0;
};
#ifdef LPBENGINE_LIB
# define LPBENGINE_EXPORT extern "C" __declspec(dllexport)
#else
# define LPBENGINE_EXPORT extern "C" __declspec(dllimport)
#endif
LPBENGINE_EXPORT IDetectorEngine* Lib_Engine_Init(void);
LPBENGINE_EXPORT void Lib_Engine_Free(IDetectorEngine* ptr);
#endif // LPBENGINE_H