245 lines
8.3 KiB
C++
245 lines
8.3 KiB
C++
#ifndef Logic_hdataprocess_H
|
||
#define Logic_hdataprocess_H
|
||
#include <QMutex>
|
||
#include <QDebug>
|
||
#include <QImage>
|
||
#include <QQueue>
|
||
#include <QVector>
|
||
#include <QMap>
|
||
#include <QMutexLocker>
|
||
#include <QJsonArray>
|
||
#include <QJsonObject>
|
||
#include <qfuture.h>
|
||
#include <QtConcurrent/qtconcurrent>
|
||
#include "base.h"
|
||
#include <QDateTime>
|
||
#pragma execution_character_set("utf-8") //能够正常显示中文字符串
|
||
typedef struct
|
||
{
|
||
QVector<QString> cameraName; // 相机名称
|
||
QVector<QString> task_index; // 当前相机的任务下标
|
||
QVector<QString> SN_dataTime; //sn+时间戳,
|
||
//or检测:保存路径,拍照面描述,相机key_第几张图,SN_时间戳
|
||
//and检测:保存路径,拍照面描述,相机key_第几张图,相机key_第几张图,SN_时间戳,SN_时间戳
|
||
//汇总:保存路径,触发信号_序号列表0,,SN_时间戳
|
||
QByteArray byte;
|
||
std::vector<cv::Mat> dstImageMat;
|
||
//拍照面描述
|
||
QString Surface;
|
||
}testData;
|
||
|
||
typedef struct
|
||
{
|
||
QVector<QString> vector_snData;
|
||
std::vector<cv::Mat> vector_mat;
|
||
QString Surface;
|
||
}SnCameraData;
|
||
|
||
// 存储sn码的数据
|
||
class HSnData
|
||
{
|
||
public:
|
||
HSnData();
|
||
void clearData();
|
||
void addSnVector(QVector<QString> snVec);
|
||
QVector<QString> getSnVector(int index);
|
||
QVector<QString> getFirstValue();
|
||
bool checkSnData();
|
||
bool removeOne();
|
||
bool deleteSnData(QString sndata); // 删除容器的
|
||
QString getSnAndDelete();
|
||
bool SetDeleteSnIndex(int index);
|
||
/**************************** NG INFO *********************/
|
||
void addNgSn(QString sn);
|
||
bool deleteNgSn();
|
||
bool deleteNgSnData(QString sndata);
|
||
bool checkNgSn(QString sn);
|
||
|
||
void setTaskDoneFlag(bool flag);
|
||
bool getTaskDoneFlag();
|
||
QString stationName;
|
||
private:
|
||
int delete_sn_index = 0;
|
||
QMutex* m_mutex;
|
||
QQueue<QVector<QString>> queue_vector_sn;
|
||
QQueue<QString> queue_ng_sn_data; // 存储NG的SN的容器
|
||
|
||
bool taskDoneFlag = true;
|
||
};
|
||
|
||
//存储算法结果的容器的结构体
|
||
typedef struct
|
||
{
|
||
QString SN_dataTime; //SN+时间戳
|
||
QString key_index; //示例:key camera1_1,algorithm1
|
||
QByteArray byte; // 存储算法结果数据
|
||
std::vector<cv::Mat> dstImageMat; // 存储算法结果图
|
||
}Algorithm_Result_Data;
|
||
|
||
// 存储算法下标的数据
|
||
typedef struct
|
||
{
|
||
QString SN_dataTime; //SN+时间戳
|
||
QString key_index; //示例:key camera1_1,algorithm1;对应原map的key值
|
||
int get_result_index = 1;
|
||
int delete_Result_index = -1; // 赋值 根据配置文件来决定
|
||
}Algorithm_Result_Data_index;
|
||
|
||
// 存储相机数据
|
||
class HCameraData
|
||
{
|
||
public:
|
||
HCameraData();
|
||
~HCameraData();
|
||
int getCameraIndex() { return m_index; } // 获取相机下标
|
||
bool initCameraVectorQueue(int camera_channel_num, int num);
|
||
bool addImageData(QString channel_index, QVector<QString> vector_sn, std::vector<cv::Mat> m_mat, QString Surface);
|
||
bool checkImageData(QString index);
|
||
void clearData(QString channel_index);
|
||
void setCameraKey(QString key) { cameraKey = key; }
|
||
void setSetSnFormat(QJsonArray array) { readSnFormatArray = array; }
|
||
QString getCameraKey() { return cameraKey; }
|
||
SnCameraData getCameraImageData(QString m_index);
|
||
QVector<QString> getSnInfo(QVector<QString> snVec);
|
||
|
||
int m_index = 0;
|
||
int image_queue_num = 0; //划分相机任务的数量
|
||
private:
|
||
QString cameraKey;
|
||
QJsonArray readSnFormatArray; // 存储sn码的格式
|
||
QVector<QVector<QQueue<SnCameraData>*>> vector_vector_queue_mat_ptr; // 存储相机图片任务的容器;QVector<QQueue<SnCameraData>*>为通道的
|
||
QMutex* m_mutex;
|
||
};
|
||
|
||
// 存储算法结果的数据
|
||
class HAlgorithmData
|
||
{
|
||
|
||
public:
|
||
HAlgorithmData();
|
||
~HAlgorithmData();
|
||
void setDeleteResultMap(QMap<QString, Algorithm_Result_Data_index> map); // 设置删除算法结果的下标
|
||
void setAlgorithmKey(QString key) { algorithmKey = key; }
|
||
void clearData();
|
||
void clearAlgorithmOneData(QString algorithmName);
|
||
void addAlgorithmData(QString cameraName_and_index, Algorithm_Result_Data result_data);
|
||
bool checkAlgorithmData(QString cameraName_and_index, QString SNdataTime);
|
||
void changeAlgorithmDataGetIndex(QString key, int index);
|
||
QString getAlgorithmKey() { return algorithmKey; }
|
||
QByteArray getAlgorithmData(QString SNdataTime, QString cameraName_and_index, QString algorithm_result_index);
|
||
QByteArray getIndexData(Algorithm_Result_Data result_data,int result_index, QString algorithm_result_index);
|
||
QStringList cameraList;
|
||
private:
|
||
QString algorithmKey;
|
||
//QQueue<Algorithm_Result_Data_index> delete_Result_index_S; // 存储删除算法中相应算法结果中的数据下标
|
||
QMap<QString, Algorithm_Result_Data_index> map_delete_Result_index;
|
||
QQueue<Algorithm_Result_Data> algorithm_resultData_S; // 示例:key camera1_1 value:Algorithm_Result_Data
|
||
QMutex* m_algorith_mutex;
|
||
};
|
||
|
||
// 保存执行算法所需要的数据
|
||
class HAlgorithmExecData
|
||
{
|
||
public:
|
||
HAlgorithmExecData();
|
||
~HAlgorithmExecData();
|
||
void clearData();
|
||
void setAlgorithmName(QString key) { algorithmName = key; }
|
||
QString getAlgorithmName() { return algorithmName; }
|
||
bool getDetectData(testData& picVec);
|
||
bool deleteDetectData();
|
||
void addDetectData(testData detectData);
|
||
|
||
QStringList cameraList;
|
||
private:
|
||
QString algorithmName;
|
||
QQueue<testData> m_detectData;
|
||
QMutex* m_mutex;
|
||
};
|
||
|
||
// 站的数据
|
||
class HStationData
|
||
{
|
||
|
||
public:
|
||
HStationData();
|
||
~HStationData();
|
||
|
||
void setStationKey(QString key) { stationKey = key; }
|
||
|
||
// 相机数据
|
||
void addCameraData(HCameraData* cameraData);
|
||
void clearData(QString channelIndex, QStringList cameraList);
|
||
void clearCameraData(QString key, QString channelIndex);
|
||
void clearAlgorithmData(QString key);
|
||
void changeAlgorithmDataGetIndex(QString key, int index);
|
||
void clearAlgorithmExecData(QString key);
|
||
void clearSnData(int index);
|
||
HCameraData* getCameraData(QString cameraKey);
|
||
|
||
// sn数据
|
||
HSnData* getSnInfoData(int index)
|
||
{
|
||
if (!sndata_list.isEmpty())
|
||
{
|
||
return sndata_list.at(index);
|
||
}
|
||
else
|
||
{
|
||
return nullptr;
|
||
}
|
||
}
|
||
void appendSnData(HSnData* sndata) { sndata_list.append(sndata); }
|
||
QQueue<cv::Mat>* getsaveImageQueueindex(int index)
|
||
{
|
||
|
||
for (int i = 0; i < saveImage_qqueue_ptr.size(); i++)
|
||
{
|
||
if (i == index)
|
||
return saveImage_qqueue_ptr.at(i);
|
||
}
|
||
return nullptr;
|
||
}
|
||
void addsaveImageQueue_ptr(QQueue<cv::Mat>* tmp_queue_mySend_imagetype)
|
||
{
|
||
saveImage_qqueue_ptr.append(tmp_queue_mySend_imagetype);
|
||
}
|
||
void addsaveImageMutex(QMutex* tmp_ptr)
|
||
{
|
||
saveImageMutex_list_ptr.append(tmp_ptr);
|
||
}
|
||
// 算法结果数据
|
||
void addAlgorithmData(HAlgorithmData* algorithmData);
|
||
bool checkCameraData(QString cameraKey, QString index);
|
||
bool checkAlgorithmResultData(QString algorithmKey, QString index,QString SN_datatime);
|
||
//增加;
|
||
//算法超时,添加配置文件读到的NG_data
|
||
void addAlgorithmResultData(QString algorithmKey, QString index, QByteArray NG_data, QString SN_datatime);
|
||
HAlgorithmData* getAlgorithmData(QString algorithmKey);
|
||
|
||
|
||
// 执行算法所需要的数据容器
|
||
void addAlgorithmExecData(HAlgorithmExecData* algorithmData);
|
||
HAlgorithmExecData* getAlgorithmExecData(QString algorithmKey);
|
||
|
||
QList<HCameraData*> getAllCameraData() { return camera_list_Ptr; }
|
||
|
||
void set_trigger_signal(QString trigger_signal);
|
||
QString get_trigger_signal();
|
||
|
||
QList<HSnData*> sndata_list; // 存储sn的容器
|
||
private:
|
||
QString stationKey;
|
||
HSnData* m_snData = nullptr;
|
||
QQueue<QVector<QString>> vectror_sn_queue;
|
||
QList<HCameraData*> camera_list_Ptr; // 工位相机列表指针
|
||
QList<HAlgorithmData*> algotithmlist_Ptr; // 当前工位算法结果汇总指针
|
||
QList<HAlgorithmExecData*> algotithmExecList_Ptr; // 执行算法所需要的数据容器指针
|
||
QList<QQueue<cv::Mat>*> saveImage_qqueue_ptr; //存图线程对应队列
|
||
QList<QMutex*> saveImageMutex_list_ptr; //存图线程对应同步锁
|
||
|
||
QString station_trigger_signal;
|
||
};
|
||
|
||
#endif // Logic_hdataprocess_H
|