/****************************************************************************** Copyright(C):2015~2018 hzleaper FileName:tpAlgorithm.h Author:zhikun wu Email:zk.wu@hzleaper.com Tools:vs2010 pc on company Created:2015/05/15 History:15:5:2015 17:51 *******************************************************************************/ #ifndef __TP_ALGORITHM_H #define __TP_ALGORITHM_H #include "baseDefine.h" #include #include #include #include #include //#include "baseStruct.h" #define ALG_SHARED_GLOBAL_KEY_APP_STATUS "app_status" #define ALG_SHARED_GLOBAL_KEY_APP_CHECKED "app_checked_status" class IAlgorithmShared { public: enum emAppStatus { APP_STATUS_DEFAULT = 0, APP_STATUS_SAMPLING = 1, }; IAlgorithmShared() {} virtual ~IAlgorithmShared() {} virtual UINT64 ILastUpdateTime() = 0; virtual QStringList IGetStringList(const QString& key) = 0; virtual int IGetInt(const QString& key, int nDef = 0) = 0; }; ///////////////////////////////////////////////////////////////////////////////////////////// #define ALG_OPTION_GLOBAL_KEY_SAMPLING_OBJECT "sampling_object" class IAlgorithmOption { public: IAlgorithmOption() {} virtual ~IAlgorithmOption() {} virtual int GetIntValue(const QString& skey, int nDefault) = 0; virtual void SetIntValue(const QString& skey, int value) = 0; virtual QString GetStringValue(const QString& skey, const QString& default = "") = 0; virtual void SetStringValue(const QString& skey, const QString& value) = 0; virtual bool Save(bool bWait = true) = 0; virtual QVariantMap VariantMap() = 0; virtual bool DbSetValue(const QString& key, int type, const QByteArray& data) = 0; virtual bool DbGetValue(const QString& key, int type, QByteArray& data) = 0; virtual bool DbDelValue(const QString& key) = 0; virtual QStringList DbGetKeysByType(int type) = 0; virtual QVariant GetValue(const QString& skey, const QVariant& def) = 0; virtual void SetValue(const QString& skey, const QVariant& value) = 0; }; typedef struct tagTP_ALGORITHM_OPTION { int algorithm; class IAlgorithmOption* pImagProcCb; } TP_ALGORITHM_OPTION; //////////////////////////////////////////////////////////////////////////////////////////// enum emTpCameraProperty{ TP_CAM_PROPERTY_NONE = 0, TP_CAM_PROPERTY_EXPOSURE = 1, TP_CAM_PROPERTY_BALANCE_RATIO_RED = 2, TP_CAM_PROPERTY_BALANCE_RATIO_GREEN = 3, TP_CAM_PROPERTY_BALANCE_RATIO_BLUE = 4, TP_CAM_PROPERTY_FOLDER_NAME = 50, TP_CAM_BITFLOW_BASE = 110, TP_CAM_BITFLOE_SAVE_CFG = TP_CAM_BITFLOW_BASE, TP_CAM_BITFLOW_ROW_RATE = TP_CAM_BITFLOW_BASE + 1, TP_CAM_BITFLOW_COMMAND = TP_CAM_BITFLOW_BASE + 9, TP_CAM_PROPERTY_FINISH = 0xFFFF }; #define TP_MAX_STRING_SIZE 260 typedef struct tagTP_CAMERA_PROPERTY { emTpCameraProperty property; long value; char szProperty[TP_MAX_STRING_SIZE]; int nErrorCode;//return by camera } TP_CAMERA_PROPERTY; class IImageObject { public: IImageObject() { } virtual ~IImageObject() { } virtual emTpColorFormat IColorFormat() = 0; //@nOutBytesPerLine: 0 means there is no valid value virtual BYTE* IImageData(int& nOutW, int& nOutH, int& nOutBitsPerPixel, int& nOutBytesPerLine) = 0; virtual int IGetId() = 0; virtual int IGetAlgorithm() = 0; virtual int IGetFrameNum() = 0; virtual int IGetTriggerCount() = 0; virtual void ISetCameroProperty(TP_CAMERA_PROPERTY& property) = 0; virtual void ISendDataToUI(void* pData) = 0; ////////////////////////////////////////////////////////// typedef void(*Comm_Callback_Func)(int cmd, BYTE* pData, int nDataLen, void* pContext); typedef struct tagDATA_TO_COMM_HEAD { char* commNames; int cmd; Comm_Callback_Func pfCallback; void* pContext; tagDATA_TO_COMM_HEAD() { commNames = NULL; cmd = 0; pfCallback = NULL; pContext = NULL; } }DATA_TO_COMM_HEAD; virtual void IDataToComm(DATA_TO_COMM_HEAD& head, char* pData, int nLen) = 0; enum emTpDefectType { TP_DEF_CLEAN, TP_DEF_RECT_F,//double for float, pData is Left, Top, Width, Height;nDataLen = sizeof(double) * 4; TP_DEF_LINE_F, TP_DEF_CIRCLE_F, TP_DEF_ELLIPSE_F, TP_DEF_POLYGON_F, TP_DEF_POLYLINE_I, }; virtual void IDrawDefect(const char* szWinName, emTpDefectType defectType, BYTE* pData, int nDataLen) = 0; virtual void IDrawDefectOrg(emTpDefectType defectType, BYTE* pData, int nDataLen) = 0; virtual void ISafeDataToUI(void* pData, int nDataLen) = 0; virtual void ISafeDataToUI(WORD type, void* pData, int nDataLen) = 0; virtual INT64 IMeterCode() = 0; virtual const char* IGetImageUtf8String() = 0; virtual void IDrawImage(QImage& image = QImage(), const char* szWinName = NULL) = 0; virtual QImage IImage() = 0; virtual const ZStringA& IDllSuffix() = 0; virtual void ISetResult(const QString& key, QVariant& val) = 0; virtual void IAccumulateResult(const QString& key, QVariant& val) = 0; virtual void IMoveToFolder(const QString& szFolder) = 0; virtual IAlgorithmShared* IGetShared() = 0; virtual void IVariantMapToUI(const QVariantMap& vMap) = 0; virtual const ZStringA& ICameraSerial() = 0; virtual const QVariant& IVarFromUI() = 0; virtual quint64 ITimeStamp() = 0; }; //pColor is ARGB, eg 0xFF010101 inline void simple_draw_image_8(IImageObject* pImgObj, uint *pColor, int nNum) { //pImgObj->IDrawImage(QImage(pBuffer, w, h, QImage::Format_ARGB32).copy()); QImage image = pImgObj->IImage(); if (QImage::Format_Indexed8 == image.format() && NULL != pColor) { QVector corFmt; for (int i = 0; i < nNum; ++i) { corFmt.append(pColor[i]); } image.setColorTable(corFmt); } pImgObj->IDrawImage(image); } class IAlgorithm { public: IAlgorithm() {} virtual ~IAlgorithm() {} virtual int IImageAnalysis(class IImageObject* pImgObj, TP_ALGORITHM_OPTION* pOpt, class IDetectorEngine* pDE) = 0; protected: }; //#define _LOAD_ALGORITHM_DLL_STATIC #ifdef ALGORITHM_EXPORTS #define ALGORITHM_API extern "C" __declspec(dllexport) #else #ifndef _LOAD_ALGORITHM_DLL_STATIC #define ALGORITHM_API extern "C" #else #define ALGORITHM_API extern "C" __declspec(dllimport) #endif #endif ALGORITHM_API IAlgorithm* Algorithm_Create(class IDetectorEngine*); ALGORITHM_API void Algorithm_Delete(IAlgorithm* pAlg); #endif