Files
handleaiuinew/HanddleAI/HandleAiUi-new/globalStruct.h
T

109 lines
2.8 KiB
C++

#include <qimage.h>
#include <qpixmap.h>
#include <opencv.hpp>
#include <qdebug.h>
#pragma execution_character_set("utf-8")
#define sColor_blue "51, 56, 69"
#define sColor_blueWithWhite "64, 68, 81"
#define sColor_blueWithBlack "46, 50, 52"
#define sColor_Red "232, 17, 35"
#define sColor_RedWithWhite "241, 112, 122"
#define sColor_GoldWithBlack "200, 165, 100"
#define sColor_Gold "223, 185, 146"
#define sColor_GoldWithWhite "250, 222, 189"
#define sColor_Black "22, 22, 22"
#define sColor_BlackWithWhite "45, 45, 45"
#define enableHandleAiModel 1
#define disableBackEndCheck 1
//窗口设置
#define windowMoveFreshRate 100//窗口移动每秒的刷新率
enum backEndError
{
dllNotFound,
triggerInitFailure,
triggerConnectionError,
camerInitFailure
};
enum initStatus
{
NotInit,
InitFailure,
InitOK,
ReInit
};
enum imgWidgetShowType
{
imgWidgetOri,
imgWidgetRes
};
struct showImgPack
{
QPixmap img;
imgWidgetShowType type;
int index = -1;
QString name = "";
};
static QImage cvMatToQImage(cv::Mat& src)
{
if (src.channels() == 1) { // if grayscale image
return QImage((uchar*)src.data, src.cols, src.rows, static_cast<int>(src.step), QImage::Format_Grayscale8).copy();
}
if (src.channels() == 3) { // if 3 channel color image
cv::Mat rgbMat;
cv::cvtColor(src, rgbMat, cv::COLOR_BGR2RGB); // invert BGR to RGB
return QImage((uchar*)rgbMat.data, src.cols, src.rows, static_cast<int>(src.step), QImage::Format_RGB888).copy();
}
return QImage();
}
static cv::Mat qImageToCvMat(const QImage& inImage)
{
switch (inImage.format())
{
case QImage::Format_RGB32:
case QImage::Format_RGB888:
{
QImage swapped = inImage;
if (inImage.format() == QImage::Format_RGB32)
{
swapped = swapped.convertToFormat(QImage::Format_RGB888);
}
cv::Mat matImg = cv::Mat(swapped.height(), swapped.width(),
CV_8UC3,
const_cast<uchar*>(swapped.bits()),
static_cast<size_t>(swapped.bytesPerLine())
);
cv::cvtColor(matImg, matImg, cv::COLOR_RGB2BGR);
return matImg.clone();
}
case QImage::Format_Indexed8:
{
cv::Mat mat(inImage.height(), inImage.width(),
CV_8UC1,
const_cast<uchar*>(inImage.bits()),
static_cast<size_t>(inImage.bytesPerLine())
);
return mat.clone();
}
default:
break;
}
return cv::Mat();
}
static void cvMatToQPixMap(cv::Mat& src,QPixmap& pixmap)
{
pixmap = QPixmap::fromImage(cvMatToQImage(src));
}
static std::string getFileName(std::string path)
{
return path.substr(path.find_last_of("\\") + 1, path.find_last_of(".") - path.find_last_of("\\") - 1);
}
Q_DECLARE_METATYPE(imgWidgetShowType)
Q_DECLARE_METATYPE(cv::Mat*)
#pragma once