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.
wheeldetect/3part/tadpole/include/tpBase/lpbdefine.h

184 lines
5.0 KiB
C

#ifndef LPBDEFINE_H
#define LPBDEFINE_H
#include "cv.h"
#include "highgui.h"
#include <QtCore>
#include <QtGui\QImage>
#include "QJsonDocument"
#include "QJsonArray"
#include "QJsonObject"
#include <opencv2/opencv.hpp>
#include <opencv2/opencv_modules.hpp>
#ifndef BYTE
typedef unsigned char BYTE;
#endif
#ifndef WORD
typedef unsigned short WORD;
#endif
#ifndef DWORD
typedef unsigned long DWORD;
#endif
//#ifndef size_t
//typedef unsigned int size_t;
//#endif
#ifndef LPWORD
typedef WORD *LPWORD;
#endif
#ifndef LPDWORD
typedef DWORD *LPDWORD;
#endif
#define BASE_MAX_FOLDER_NAME_SIZE 64
#define BASE_MAX_FILE_NAME_SIZE 64
#define LP_DETECTOR_BUSSINESS_CONFIG_DIR "./config/"
#define LP_DETECTOR_BUSSINESS_IMAGE_DIR "./images/"
#define LP_DETECTOR_BUSSINESS_IN_PARAM_FILE_DIR "./paramfiles/"
#define LP_DETECTOR_BUSSINESS_CONFIG_SOLUTIONMGR_FILE "./config/solutionmgr.json"
#define LP_DETECTOR_BUSSINESS_CONFIG_DEVICEMGR_FILE "./config/devicemgr.json"
#define LP_DETECTOR_BUSSINESS_DB "info.db"
#define LP_DETECTOR_BUSSINESS_CONFIG_FILE_NAME "systemInfo.ini"
#define LP_DETECTOR_BUSSINESS_CONFIG_SOLUTIONMGR_INFO_FILE "./solutions/info.json"
#define LP_DETECTOR_BUSSINESS_CONFIG_SOLUTION_DIR "./solutions/"
#define LP_DETECTOR_BUSSINESS_CONFIG_ALGO_DIR "./algorithmLib/"
#define LP_DETECTOR_BUSSINESS_CONFIG_PARAMSHARE_FILE "./config/paramshare.json"
#define LP_DETECTOR_INVALID_ID 0xffffffff
#define LP_DETECTOR_ALGO_PARAM_INPUT_ROI "roi"
#define LP_DETECTOR_ALGO_PARAM_RELY_COORDINATE "rely_coordinate"
#define LP_DETECTOR_ALGO_PARAM_RELATIVE_ROI "relative_roi"
const DWORD LP_DETECTOR_DEVICE_SERIALPORT_BASE = 0x0210FFFF;
namespace EngineBase
{
static cv::Mat QImage2cvMat(QImage image)
{
cv::Mat mat;
switch (image.format())
{
case QImage::Format_ARGB32:
case QImage::Format_RGB32:
case QImage::Format_ARGB32_Premultiplied:
mat = cv::Mat(image.height(), image.width(), CV_8UC4, (void*)image.constBits(), image.bytesPerLine());
break;
case QImage::Format_RGB888:
mat = cv::Mat(image.height(), image.width(), CV_8UC3, (void*)image.constBits(), image.bytesPerLine());
cv::cvtColor(mat, mat, CV_BGR2RGB);
break;
case QImage::Format_Indexed8:
mat = cv::Mat(image.height(), image.width(), CV_8UC1, (void*)image.constBits(), image.bytesPerLine());
break;
}
return mat;
}
static QImage convMat2QImage(cv::Mat & mat)
{
//qDebug() << "ERROR: Mat could not be converted to QImage.";
// 8-bits unsigned, NO. OF CHANNELS = 1
if (mat.type() == CV_8UC1)
{
QImage image(mat.cols, mat.rows, QImage::Format_Indexed8);
// Set the color table (used to translate colour indexes to qRgb values)
image.setColorCount(256);
for (int i = 0; i < 256; i++)
{
image.setColor(i, qRgb(i, i, i));
}
// Copy input Mat
uchar *pSrc = mat.data;
for (int row = 0; row < mat.rows; row++)
{
uchar *pDest = image.scanLine(row);
memcpy(pDest, pSrc, mat.cols);
pSrc += mat.step;
}
return image;
}
// 8-bits unsigned, NO. OF CHANNELS = 3
else if (mat.type() == CV_8UC3)
{
// Copy input Mat
const uchar *pSrc = (const uchar*)mat.data;
// Create QImage with same dimensions as input Mat
QImage image(pSrc, mat.cols, mat.rows, mat.step, QImage::Format_RGB888);
return image.rgbSwapped();
}
else if (mat.type() == CV_8UC4)
{
qDebug() << "CV_8UC4";
// Copy input Mat
const uchar *pSrc = (const uchar*)mat.data;
// Create QImage with same dimensions as input Mat
QImage image(pSrc, mat.cols, mat.rows, mat.step, QImage::Format_ARGB32);
return image.copy();
}
else
{
qDebug() << "ERROR: Mat could not be converted to QImage.";
return QImage();
}
}
static bool DeleteDir(const QString &dirName)
{
if (dirName.isEmpty())
{
return false;
}
QDir dir(dirName);
if (!dir.exists())
{
return true;
}
QString srcPath = QDir::toNativeSeparators(dirName);
if (!srcPath.endsWith(QDir::separator()))
srcPath += QDir::separator();
QStringList fileNames = dir.entryList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden);
bool error = false;
for (QStringList::size_type i = 0; i != fileNames.size(); ++i)
{
QString filePath = srcPath + fileNames.at(i);
QFileInfo fileInfo(filePath);
if (fileInfo.isFile() || fileInfo.isSymLink())
{
QFile::setPermissions(filePath, QFile::WriteOwner);
if (!QFile::remove(filePath))
{
error = true;
}
}
else if (fileInfo.isDir())
{
if (!DeleteDir(filePath))
{
error = true;
}
}
}
if (!dir.rmdir(QDir::toNativeSeparators(dir.path())))
{
qWarning() << "remove dir" << dir.path() << " faild!";
error = true;
}
return !error;
}
}
#endif // LPBDEFINE_H