|
|
|
|
|
#ifndef __BASE_STRUCT_H
|
|
|
|
|
|
#define __BASE_STRUCT_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "baseDefine.h"
|
|
|
|
|
|
#include "baseConstant.h"
|
|
|
|
|
|
#include "iAlgorithm.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define BASE_MAX_FILE_PATH 260
|
|
|
|
|
|
#define BASE_MAX_FOLDER_NAME_SIZE 64
|
|
|
|
|
|
#define BASE_MAX_FILE_NAME_SIZE 64
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct tagTP_CORE_SETTING{
|
|
|
|
|
|
int threadsCount;
|
|
|
|
|
|
int imageShowType;
|
|
|
|
|
|
}TP_CORE_SETTING;
|
|
|
|
|
|
|
|
|
|
|
|
enum emTpDeviceType {
|
|
|
|
|
|
DEV_CAM_NONE = 0,
|
|
|
|
|
|
DEV_CAM_VIRTUAL = 100,
|
|
|
|
|
|
DEV_CAM_VIRTUAL_FOLDER = 100,
|
|
|
|
|
|
DEV_CAM_BITFLOW = 110,
|
|
|
|
|
|
DEV_CAM_BITFLOW_BI = 110,
|
|
|
|
|
|
DEV_CAM_GIGE = 120,
|
|
|
|
|
|
DEV_CAM_USB = 130,
|
|
|
|
|
|
DEV_CAM_HIK = 140,
|
|
|
|
|
|
DEV_CAM_VIMBA = 150,
|
|
|
|
|
|
DEV_CAM_BAUMER = 160,
|
|
|
|
|
|
DEV_CAM_ADLINK = 170,
|
|
|
|
|
|
DEV_CAM_DAHUA = 180,
|
|
|
|
|
|
DEV_CAM_BASLER = 190,
|
|
|
|
|
|
DEV_CAM_PTGRAY = 200,
|
|
|
|
|
|
DEV_CAM_EURESYS = 220,
|
|
|
|
|
|
DEV_CAM_DALSA = 230,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const QMap<emTpDeviceType, QString> gCameraNamesMap = {
|
|
|
|
|
|
{ DEV_CAM_NONE, "Unknown(0)" },
|
|
|
|
|
|
{ DEV_CAM_VIRTUAL, "Virtual Camera(100)" },
|
|
|
|
|
|
{ DEV_CAM_VIRTUAL_FOLDER, "Virtual Camera(100)" },
|
|
|
|
|
|
{ DEV_CAM_BITFLOW, "BitFlow(110)" },
|
|
|
|
|
|
{ DEV_CAM_BITFLOW_BI, "BitFlow(110)" },
|
|
|
|
|
|
{ DEV_CAM_GIGE, "Gige(120)" },
|
|
|
|
|
|
{ DEV_CAM_USB, "USB Camera(130)" },
|
|
|
|
|
|
{ DEV_CAM_HIK, "HIK(140)" },
|
|
|
|
|
|
{ DEV_CAM_VIMBA, "Vimba(150)" },
|
|
|
|
|
|
{ DEV_CAM_BAUMER, "Baumer(160)" },
|
|
|
|
|
|
{ DEV_CAM_ADLINK, "AdLink(170)" },
|
|
|
|
|
|
{ DEV_CAM_DAHUA, "DaHua(180)" },
|
|
|
|
|
|
{ DEV_CAM_BASLER, "Basler(190)" },
|
|
|
|
|
|
{ DEV_CAM_PTGRAY, "PtGray(200)" },
|
|
|
|
|
|
{ DEV_CAM_EURESYS, "Euresys(220)" },
|
|
|
|
|
|
{ DEV_CAM_DALSA, "Dalsa(230)" }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define TP_STRING_MAX_SIZE 256
|
|
|
|
|
|
|
|
|
|
|
|
enum emTpCameraStatus{
|
|
|
|
|
|
TP_CAMERA_STATUS_UNINIT = 0, // 未初始化(刚从配置文件加载)
|
|
|
|
|
|
TP_CAMERA_STATUS_INITED = 1, // 已初始化(即加载DLL成功)
|
|
|
|
|
|
TP_CAMERA_STATUS_OPENED = 2, // 已打开
|
|
|
|
|
|
TP_CAMERA_STATUS_STARTED = 3, // 运行中
|
|
|
|
|
|
TP_CAMERA_STATUS_STOPPED = 4, // 暂停
|
|
|
|
|
|
TP_CAMERA_STATUS_CLOSED = 5, // 已关闭
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const QMap<emTpCameraStatus, QString> gCameraStatusMap = {
|
|
|
|
|
|
{ TP_CAMERA_STATUS_UNINIT, "Uninitialized" },
|
|
|
|
|
|
{ TP_CAMERA_STATUS_INITED, "Initialized" },
|
|
|
|
|
|
{ TP_CAMERA_STATUS_OPENED, "Opened" },
|
|
|
|
|
|
{ TP_CAMERA_STATUS_STARTED, "Running" },
|
|
|
|
|
|
{ TP_CAMERA_STATUS_STOPPED, "Paused" },
|
|
|
|
|
|
{ TP_CAMERA_STATUS_CLOSED, "Closed" }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct tagTP_CAMERA_OPTION {
|
|
|
|
|
|
tagTP_CAMERA_OPTION()
|
|
|
|
|
|
:id(0), deviceType(0), save(0), loop(0), width(0),
|
|
|
|
|
|
height(0), zoom(0), format(TP_COLOR_NONE), algorithm(0), exposure(0),
|
|
|
|
|
|
boardType(0), boardNum(0), gain(0), bIgnoreImage(false),
|
|
|
|
|
|
bNeedRgbSwapped(false), bAutoOpen(true), bAutoPush(true),
|
|
|
|
|
|
status(TP_CAMERA_STATUS_UNINIT)
|
|
|
|
|
|
{ }
|
|
|
|
|
|
int id;
|
|
|
|
|
|
int deviceType;
|
|
|
|
|
|
BYTE save;
|
|
|
|
|
|
BYTE loop;//
|
|
|
|
|
|
BYTE reserve[2];
|
|
|
|
|
|
QString showName;
|
|
|
|
|
|
QString uniqueName;
|
|
|
|
|
|
int width;
|
|
|
|
|
|
int height;
|
|
|
|
|
|
int zoom;
|
|
|
|
|
|
emTpColorFormat format;
|
|
|
|
|
|
QString folder;
|
|
|
|
|
|
QString saveImgSuffix;
|
|
|
|
|
|
int algorithm;
|
|
|
|
|
|
QString relyOnCamera;
|
|
|
|
|
|
long exposure;
|
|
|
|
|
|
int boardType;
|
|
|
|
|
|
int boardNum;
|
|
|
|
|
|
long gain;
|
|
|
|
|
|
QString dllsuffix;
|
|
|
|
|
|
QString sBoardName;
|
|
|
|
|
|
QString sBoardConfigFile;
|
|
|
|
|
|
|
|
|
|
|
|
// used inner
|
|
|
|
|
|
bool bIgnoreImage;
|
|
|
|
|
|
QStringList* pSerials;
|
|
|
|
|
|
bool bNeedRgbSwapped;
|
|
|
|
|
|
QString macAddress;
|
|
|
|
|
|
bool bAutoOpen;
|
|
|
|
|
|
QString cameraFilePath;
|
|
|
|
|
|
bool bAutoPush; // 默认一旦得到图片,就直接push进pool。
|
|
|
|
|
|
|
|
|
|
|
|
// camera status - used for app inside
|
|
|
|
|
|
emTpCameraStatus status;
|
|
|
|
|
|
|
|
|
|
|
|
bool operator==(const tagTP_CAMERA_OPTION& rhs)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (id == rhs.id) && (deviceType == rhs.deviceType) &&
|
|
|
|
|
|
(save == rhs.save) && (loop == rhs.loop) &&
|
|
|
|
|
|
(showName == rhs.showName) &&
|
|
|
|
|
|
(uniqueName == rhs.uniqueName) &&
|
|
|
|
|
|
(zoom == rhs.zoom) && (format == rhs.format) &&
|
|
|
|
|
|
(folder == rhs.folder) &&
|
|
|
|
|
|
(saveImgSuffix == rhs.saveImgSuffix) &&
|
|
|
|
|
|
(algorithm == rhs.algorithm) && (relyOnCamera == rhs.relyOnCamera) &&
|
|
|
|
|
|
(exposure == rhs.exposure) && (boardType == rhs.boardType) &&
|
|
|
|
|
|
(boardNum == rhs.boardNum) &&
|
|
|
|
|
|
(gain == rhs.gain) &&
|
|
|
|
|
|
(dllsuffix == rhs.dllsuffix) &&
|
|
|
|
|
|
(sBoardName == rhs.sBoardName) &&
|
|
|
|
|
|
(sBoardConfigFile == rhs.sBoardConfigFile) &&
|
|
|
|
|
|
(bAutoPush == rhs.bAutoPush) &&
|
|
|
|
|
|
(bNeedRgbSwapped == rhs.bNeedRgbSwapped);
|
|
|
|
|
|
}
|
|
|
|
|
|
}TP_CAMERA_OPTION;
|
|
|
|
|
|
|
|
|
|
|
|
enum emTpCommType {
|
|
|
|
|
|
TP_COMM_TYPE_NO = 0,
|
|
|
|
|
|
TP_COMM_TYPE_SERIAL = 1,
|
|
|
|
|
|
TP_COMM_TYPE_USB = 2,
|
|
|
|
|
|
TP_COMM_TYPE_TCP_CLIENT = 3, // 主机作为客户端
|
|
|
|
|
|
TP_COMM_TYPE_TCP_SERVER = 4, // 主机作为服务端
|
|
|
|
|
|
TP_COMM_TYPE_TCP_CLIENT_SESSION = 5, // 主机作为服务端,接受的客户端会话
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum emTpDeviceTriggerMode {
|
|
|
|
|
|
DEV_TRIGGER_MODE_STOP = 0,
|
|
|
|
|
|
DEV_TRIGGER_MODE_OUT = 1,
|
|
|
|
|
|
DEV_TRIGGER_MODE_AUTO = 2,
|
|
|
|
|
|
DEV_TRIGGER_MODE_FIXED_AUTO = 3,
|
|
|
|
|
|
DEV_TRIGGER_MODE_SOFT = 4,
|
|
|
|
|
|
// DEV_TRIGGER_MODE_MANUAL = 3,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum emTpTriggerDirection {
|
|
|
|
|
|
TRIGGER_DIRECT_FOREWARD = 0,
|
|
|
|
|
|
TRIGGER_DIRECT_BACKWARD = 1,
|
|
|
|
|
|
TRIGGER_DIRECT_REPEAT = 2,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct tagTP_CAMERAPOOL_OPTION {
|
|
|
|
|
|
emTpDeviceTriggerMode triggerMode;
|
|
|
|
|
|
emTpTriggerDirection triggerDirection;
|
|
|
|
|
|
int frameRate;
|
|
|
|
|
|
int fixedFrames;
|
|
|
|
|
|
}TP_CAMERAPOOL_OPTION;
|
|
|
|
|
|
|
|
|
|
|
|
static const QMap<emTpColorFormat, QString> gColorNameMap = {
|
|
|
|
|
|
{ TP_COLOR_NONE, "None" },
|
|
|
|
|
|
{ TP_COLOR_Y800, "GRAY8" },
|
|
|
|
|
|
{ TP_COLOR_RGB24, "RGB24" },
|
|
|
|
|
|
{ TP_COLOR_RGB32, "RGB32" },
|
|
|
|
|
|
{ TP_COLOR_Y16, "GRAY16" },
|
|
|
|
|
|
{ TP_COLOR_RGB48, "RGB48" },
|
|
|
|
|
|
{ TP_COLOR_BGR24, "BGR24" },
|
|
|
|
|
|
{ TP_COLOR_BGR32, "BGR32" }
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define TP_LOG_TAIL " - " << __FUNCTION__
|
|
|
|
|
|
#define TP_DEBUG(msg) qDebug() << msg << TP_LOG_TAIL;
|
|
|
|
|
|
#define TP_WARN(msg) qWarning() << msg << TP_LOG_TAIL;
|
|
|
|
|
|
#define TP_ERROR(msg) qCritical() << msg << TP_LOG_TAIL;
|
|
|
|
|
|
|
|
|
|
|
|
//global functions
|
|
|
|
|
|
namespace TP_FUNCS
|
|
|
|
|
|
{
|
|
|
|
|
|
#define F_INLINE inline
|
|
|
|
|
|
F_INLINE QString ImageFileName(DWORD nFrameNumber, const TP_CAMERA_OPTION* pCamOpt, const char* szSuffix)
|
|
|
|
|
|
{
|
|
|
|
|
|
QStringList invaldcha = (QStringList() << "\\" << "/" << "*" << "?" << "<" << ">" << "|" << ":");
|
|
|
|
|
|
QDateTime dt = QDateTime::currentDateTime();
|
|
|
|
|
|
QString strCamName = pCamOpt->uniqueName;
|
|
|
|
|
|
foreach(const QString &str, invaldcha) {
|
|
|
|
|
|
strCamName.remove(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
QString strName = pCamOpt->folder + strCamName
|
|
|
|
|
|
+ "_" + dt.toString("yyyy_MM_dd_hh_mm_ss_zzz") + "_"
|
|
|
|
|
|
+ QString::number(nFrameNumber) + szSuffix/*".BMP"*/;
|
|
|
|
|
|
|
|
|
|
|
|
return strName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
F_INLINE QString ImageFileName(DWORD nFrameNumber, const TP_CAMERA_OPTION* pCamOpt)
|
|
|
|
|
|
{
|
|
|
|
|
|
QStringList invaldcha = (QStringList() << "\\" << "/" << "*" << "?" << "<" << ">" << "|" << ":");
|
|
|
|
|
|
QDateTime dt = QDateTime::currentDateTime();
|
|
|
|
|
|
QString strCamName = pCamOpt->uniqueName;
|
|
|
|
|
|
//foreach(const QString &str, invaldcha) {
|
|
|
|
|
|
// strCamName.remove(str);
|
|
|
|
|
|
//}
|
|
|
|
|
|
strCamName.remove(":");
|
|
|
|
|
|
QString strName = pCamOpt->folder + strCamName
|
|
|
|
|
|
+ "_" + dt.toString("yyyy_MM_dd_hh_mm_ss_zzz") + "_"
|
|
|
|
|
|
+ QString::number(nFrameNumber) + pCamOpt->saveImgSuffix;
|
|
|
|
|
|
|
|
|
|
|
|
return strName;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
F_INLINE emTpColorFormat FromQImageFormat(const QImage &image)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (QImage::Format_RGB32 == image.format())
|
|
|
|
|
|
{
|
|
|
|
|
|
return TP_COLOR_RGB32;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (QImage::Format_RGB888 == image.format())
|
|
|
|
|
|
{
|
|
|
|
|
|
return TP_COLOR_RGB24;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (QImage::Format_Indexed8 == image.format())
|
|
|
|
|
|
{
|
|
|
|
|
|
return TP_COLOR_Y800;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (QImage::Format_RGB16 == image.format())
|
|
|
|
|
|
{
|
|
|
|
|
|
return TP_COLOR_Y16;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (QImage::Format_ARGB32 == image.format())
|
|
|
|
|
|
{
|
|
|
|
|
|
return TP_COLOR_RGB48;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return TP_COLOR_NONE;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
F_INLINE QImage::Format ToQImageFormat(emTpColorFormat colorFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (TP_COLOR_RGB32 == colorFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return QImage::Format_RGB32;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (TP_COLOR_RGB24 == colorFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return QImage::Format_RGB888;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (TP_COLOR_Y800 == colorFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return QImage::Format_Indexed8;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (TP_COLOR_Y16 == colorFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return QImage::Format_RGB16;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (TP_COLOR_RGB48 == colorFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return QImage::Format_ARGB32;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return QImage::Format_Invalid;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
F_INLINE int BitsPerPixels(emTpColorFormat colorFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (TP_COLOR_RGB32 == colorFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 32;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (TP_COLOR_RGB24 == colorFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 24;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (TP_COLOR_Y800 == colorFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 8;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (TP_COLOR_Y16 == colorFormat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return 16;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
F_INLINE bool isValidImgSuffix(const QString& str)
|
|
|
|
|
|
{
|
|
|
|
|
|
static QRegExp rx("(\\w*|\\w*\\*)\\.(?:bmp|jpeg|jpg|png)", Qt::CaseInsensitive);
|
|
|
|
|
|
return rx.exactMatch(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// IPV4 only
|
|
|
|
|
|
F_INLINE bool isValidIPAddress(const QString& str)
|
|
|
|
|
|
{
|
|
|
|
|
|
// [0,255].[0,255].[0,255].[0,255]
|
|
|
|
|
|
static QRegExp rx("((2[0-4]\\d|25[0-5]|[01]?\\d\\d?).){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)");
|
|
|
|
|
|
return rx.exactMatch(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|