1076 lines
30 KiB
C++
1076 lines
30 KiB
C++
#include "hdataprocess.h"
|
|
#include "struct.h"
|
|
HCameraData::HCameraData()
|
|
{
|
|
m_mutex = new QMutex;
|
|
}
|
|
|
|
HCameraData::~HCameraData()
|
|
{
|
|
if(m_mutex)
|
|
{
|
|
delete m_mutex;
|
|
m_mutex = nullptr;
|
|
}
|
|
|
|
for( int i = 0; i < camera_vector_queue_vector_mat_ptr.size(); i++ )
|
|
{
|
|
if(camera_vector_queue_vector_mat_ptr.at(i))
|
|
{
|
|
delete camera_vector_queue_vector_mat_ptr.at(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool HCameraData::initCameraVectorQueue(int num)
|
|
{
|
|
if( num <= 0 || num > 50 )
|
|
{
|
|
qCritical() << "[Error] " << " num is error! num:" << num;
|
|
return false;
|
|
}
|
|
|
|
image_queue_num = num;
|
|
for( int i = 0; i < num; i++ )
|
|
{
|
|
QQueue<std::vector<cv::Mat>> *queue_mats_ptr = new QQueue<std::vector<cv::Mat>>;
|
|
camera_vector_queue_vector_mat_ptr.append(queue_mats_ptr);
|
|
}
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " ----------------------- len:" << camera_vector_queue_vector_mat_ptr.length();
|
|
return true;
|
|
}
|
|
|
|
bool HCameraData::checkImageData(QString index)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
int m_value = index.toInt();
|
|
if (camera_vector_queue_vector_mat_ptr.size() == 0)
|
|
return false;
|
|
if(m_value>= camera_vector_queue_vector_mat_ptr.size())
|
|
return false;
|
|
QQueue<std::vector<cv::Mat>> *queue_ptr = camera_vector_queue_vector_mat_ptr.at(m_value);
|
|
if ( queue_ptr )
|
|
{
|
|
if ( !queue_ptr->isEmpty() )
|
|
{
|
|
return true; // 获取数据
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
std::vector<cv::Mat> HCameraData::getCameraImageData(QString m_index)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
std::vector<cv::Mat> picVec;
|
|
int index = m_index.toInt();
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " index:" <<index << " camera_vector_queue_vector_mat_ptr len:" << camera_vector_queue_vector_mat_ptr.length();
|
|
if ( camera_vector_queue_vector_mat_ptr.size() >= index && index >= 0 )
|
|
{
|
|
QQueue<std::vector<cv::Mat>> *queue_ptr = camera_vector_queue_vector_mat_ptr.at(index);
|
|
if ( queue_ptr )
|
|
{
|
|
if ( !queue_ptr->isEmpty() )
|
|
{
|
|
picVec = queue_ptr->dequeue();
|
|
// qDebug() << "[INFO] " << " picVec len:" << picVec.size();
|
|
return picVec; // 获取数据
|
|
}
|
|
}
|
|
}
|
|
return picVec;
|
|
}
|
|
|
|
void HCameraData::clearData()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
int size = camera_vector_queue_vector_mat_ptr.size();
|
|
for (int i = 0; i < size; i++)
|
|
{
|
|
QQueue<std::vector<cv::Mat>>* queue_ptr = camera_vector_queue_vector_mat_ptr.at(i);
|
|
queue_ptr->clear();
|
|
}
|
|
m_index = 0;
|
|
}
|
|
|
|
int HCameraData::GetMatNum()
|
|
{
|
|
return m_index;
|
|
}
|
|
|
|
bool HCameraData::addImageData( std::vector<cv::Mat> data )
|
|
{
|
|
QMutexLocker locker ( m_mutex );
|
|
qDebug() << " cameraKey:" << cameraKey << " m_index/ image_queue_num:" << m_index << " /:" << image_queue_num;
|
|
if ( m_index >= image_queue_num )
|
|
{
|
|
m_index = 0;
|
|
}
|
|
|
|
if(camera_vector_queue_vector_mat_ptr.at(m_index))
|
|
{
|
|
camera_vector_queue_vector_mat_ptr.at(m_index)->append(data);
|
|
m_index++;
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
////////////////////////////////
|
|
HSnData::HSnData()
|
|
{
|
|
m_mutex = new QMutex;
|
|
}
|
|
|
|
void HSnData::addSnInfo(SNINFO* snInfo)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
sninfo_list.push_back(snInfo);
|
|
}
|
|
|
|
void HSnData::checkPhotoPoint()
|
|
{
|
|
|
|
}
|
|
|
|
int HSnData::getSnInfo(QString stationKey, QString cameraKey, QString& sn, QString& dateTime, int& cameraIndex, int& picIndex,QString& GYid)
|
|
{
|
|
|
|
int result = -1;
|
|
QMutexLocker locker(m_mutex);
|
|
if (stationKey == "Station1")
|
|
{
|
|
if (sninfo_list.size() < 1)
|
|
qDebug() << "pic do not find sn info";
|
|
for (int i = 0; i < sninfo_list.size(); i++)
|
|
{
|
|
if (sninfo_list[i]->sn1 != "" && sninfo_list[i]->sn2 != "")//error
|
|
{
|
|
if (sninfo_list[i]->getcamreaIndexMapValue(cameraKey) != camreaPicNumMap.value(cameraKey))
|
|
{
|
|
result = i;
|
|
sninfo_list[i]->updatecamreaIndexMap(cameraKey, sninfo_list[i]->getcamreaIndexMapValue(cameraKey) + 1);
|
|
picIndex = sninfo_list[i]->getcamreaIndexMapValue(cameraKey);
|
|
if (picIndex == 1 || picIndex == 4)
|
|
{
|
|
sn = sninfo_list[i]->sn1;
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
if (picIndex > 2)
|
|
{
|
|
cameraIndex = 2;
|
|
}
|
|
else
|
|
{
|
|
cameraIndex = 1;
|
|
}
|
|
|
|
picIndex = 1;
|
|
}
|
|
else if (picIndex == 2 || picIndex == 3)
|
|
{
|
|
sn = sninfo_list[i]->sn2;
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
if (picIndex > 2)
|
|
{
|
|
cameraIndex = 2;
|
|
}
|
|
else
|
|
{
|
|
cameraIndex = 1;
|
|
}
|
|
|
|
picIndex = 2;
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
qDebug() <<"stationKey:" << stationKey <<" sn info size:" << sninfo_list.size();;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
else if (stationKey == "Station2")
|
|
{
|
|
if (sninfo_list.size() < 1)
|
|
qDebug() << "pic do not find sn info";
|
|
for (int i = 0; i < sninfo_list.size(); i++)
|
|
{
|
|
if (sninfo_list[i]->sn1 != "" && sninfo_list[i]->sn2 != "")
|
|
{
|
|
if (sninfo_list[i]->getcamreaIndexMapValue(cameraKey) != camreaPicNumMap.value(cameraKey))
|
|
{
|
|
result = i;
|
|
sninfo_list[i]->updatecamreaIndexMap(cameraKey, sninfo_list[i]->getcamreaIndexMapValue(cameraKey) + 1);
|
|
picIndex = sninfo_list[i]->getcamreaIndexMapValue(cameraKey);
|
|
if (picIndex == 1 || picIndex == 4)
|
|
{
|
|
sn = sninfo_list[i]->sn2;
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
if (picIndex > 2)
|
|
{
|
|
cameraIndex = 2;
|
|
}
|
|
else
|
|
{
|
|
cameraIndex = 1;
|
|
}
|
|
|
|
picIndex = 2;
|
|
}
|
|
else if (picIndex == 2 || picIndex == 3)
|
|
{
|
|
sn = sninfo_list[i]->sn1;
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
if (picIndex > 2)
|
|
{
|
|
cameraIndex = 2;
|
|
}
|
|
else
|
|
{
|
|
cameraIndex = 1;
|
|
}
|
|
|
|
picIndex = 1;
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
qDebug() << "stationKey:" << stationKey << " sn info size:" << sninfo_list.size();;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
else if (stationKey == "Station3")
|
|
{
|
|
if (sninfo_list.size() < 1)
|
|
qDebug() << "pic do not find sn info";
|
|
for (int i = 0; i < sninfo_list.size(); i++)
|
|
{
|
|
if (sninfo_list[i]->sn1 != "" && sninfo_list[i]->sn2 != "")
|
|
{
|
|
if (sninfo_list[i]->getcamreaIndexMapValue(cameraKey) != camreaPicNumMap.value(cameraKey))
|
|
{
|
|
result = i;
|
|
sninfo_list[i]->updatecamreaIndexMap(cameraKey, sninfo_list[i]->getcamreaIndexMapValue(cameraKey) + 1);
|
|
picIndex = sninfo_list[i]->getcamreaIndexMapValue(cameraKey);
|
|
if (picIndex == 1)
|
|
{
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
cameraIndex = 1;
|
|
if (cameraKey == m_camera3Key || cameraKey == m_camera1Key)
|
|
{
|
|
sn = sninfo_list[i]->sn2;
|
|
picIndex = 2;
|
|
|
|
}
|
|
else
|
|
{
|
|
sn = sninfo_list[i]->sn1;
|
|
picIndex = 1;
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
|
|
sn = sninfo_list[i]->sn1;
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
cameraIndex = 2;
|
|
if (cameraKey == m_camera3Key || cameraKey == m_camera1Key)
|
|
{
|
|
sn = sninfo_list[i]->sn1;
|
|
picIndex = 1;
|
|
}
|
|
else
|
|
{
|
|
sn = sninfo_list[i]->sn2;
|
|
picIndex = 2;
|
|
}
|
|
|
|
}
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
//qDebug() << "stationKey:" << stationKey << " sn info size:" << sninfo_list.size();;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
else if (stationKey == "Station4")
|
|
{
|
|
if (sninfo_list.size() < 1)
|
|
qDebug() << "pic do not find sn info";
|
|
|
|
for (int i = 0; i < sninfo_list.size(); i++)
|
|
{
|
|
if (sninfo_list[i]->sn1 != "" && sninfo_list[i]->sn2 != "")
|
|
{
|
|
if (sninfo_list[i]->getcamreaIndexMapValue(cameraKey) != camreaPicNumMap.value(cameraKey))
|
|
{
|
|
result = i;
|
|
sninfo_list[i]->updatecamreaIndexMap(cameraKey, sninfo_list[i]->getcamreaIndexMapValue(cameraKey) + 1);
|
|
picIndex = sninfo_list[i]->getcamreaIndexMapValue(cameraKey);
|
|
if (picIndex == 1 || picIndex == 4)
|
|
{
|
|
sn = sninfo_list[i]->sn2;
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
if (picIndex > 2)
|
|
{
|
|
cameraIndex = 2;
|
|
}
|
|
else
|
|
{
|
|
cameraIndex = 1;
|
|
}
|
|
|
|
picIndex = 2;
|
|
}
|
|
else if (picIndex == 2 || picIndex == 3)
|
|
{
|
|
sn = sninfo_list[i]->sn1;
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
if (picIndex > 2)
|
|
{
|
|
cameraIndex = 2;
|
|
}
|
|
else
|
|
{
|
|
cameraIndex = 1;
|
|
}
|
|
|
|
picIndex = 1;
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
//qDebug() << "stationKey:" << stationKey << " sn info size:" << sninfo_list.size();;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
else if (stationKey == "Station5")
|
|
{
|
|
if (sninfo_list.size() < 1)
|
|
qDebug() << "pic do not find sn info";
|
|
|
|
for (int i = 0; i < sninfo_list.size(); i++)
|
|
{
|
|
if (sninfo_list[i]->sn1 != "" && sninfo_list[i]->sn2 != "")
|
|
{
|
|
if (sninfo_list[i]->getcamreaIndexMapValue(cameraKey) != camreaPicNumMap.value(cameraKey))
|
|
{
|
|
result = i;
|
|
sninfo_list[i]->updatecamreaIndexMap(cameraKey, sninfo_list[i]->getcamreaIndexMapValue(cameraKey) + 1);
|
|
picIndex = sninfo_list[i]->getcamreaIndexMapValue(cameraKey);
|
|
if (picIndex < camreaPicNumMap.value(cameraKey) / 2 + 1)
|
|
{
|
|
sn = sninfo_list[i]->sn1;
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
cameraIndex = picIndex;
|
|
|
|
picIndex = 1;
|
|
}
|
|
else
|
|
{
|
|
sn = sninfo_list[i]->sn2;
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
cameraIndex = picIndex - camreaPicNumMap.value(cameraKey)/2;
|
|
|
|
picIndex = 2;
|
|
}
|
|
|
|
if (cameraKey == m_camera7Key)
|
|
{
|
|
if (cameraIndex == 3)
|
|
{
|
|
GYid = "1";
|
|
}
|
|
else if (cameraIndex == 4)
|
|
{
|
|
GYid = "2";
|
|
}
|
|
|
|
else
|
|
GYid = QString::number(cameraIndex);
|
|
|
|
}
|
|
else
|
|
GYid = QString::number(cameraIndex);
|
|
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
//qDebug() << "stationKey:" << stationKey << " sn info size:" << sninfo_list.size();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (stationKey == "Station10"|| stationKey == "station10")
|
|
{
|
|
if (sninfo_list.size() < 1)
|
|
qDebug() << "pic do not find sn info";
|
|
|
|
for (int i = 0; i < sninfo_list.size(); i++)
|
|
{
|
|
if (sninfo_list[i]->sn1 != "" && sninfo_list[i]->sn2 != "")
|
|
{
|
|
if (sninfo_list[i]->getcamreaIndexMapValue(cameraKey) != camreaPicNumMap.value(cameraKey))
|
|
{
|
|
result = i;
|
|
sninfo_list[i]->updatecamreaIndexMap(cameraKey, sninfo_list[i]->getcamreaIndexMapValue(cameraKey) + 1);
|
|
picIndex = sninfo_list[i]->getcamreaIndexMapValue(cameraKey);
|
|
if (picIndex < camreaPicNumMap.value(cameraKey) / 2 + 1)
|
|
{
|
|
sn = sninfo_list[i]->sn1;
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
cameraIndex = picIndex;
|
|
|
|
picIndex = 1;
|
|
}
|
|
else
|
|
{
|
|
sn = sninfo_list[i]->sn2;
|
|
dateTime = sninfo_list[i]->dataTime;
|
|
cameraIndex = picIndex - camreaPicNumMap.value(cameraKey) / 2;
|
|
|
|
picIndex = 2;
|
|
}
|
|
|
|
if (cameraKey == m_camera7Key)
|
|
{
|
|
if (cameraIndex == 3)
|
|
{
|
|
GYid = "1";
|
|
}
|
|
else if (cameraIndex == 4)
|
|
{
|
|
GYid = "2";
|
|
}
|
|
|
|
else
|
|
GYid = QString::number(cameraIndex);
|
|
|
|
}
|
|
else
|
|
GYid = QString::number(cameraIndex);
|
|
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
//qDebug() << "stationKey:" << stationKey << " sn info size:" << sninfo_list.size();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
qDebug() << "pic do not find Station"<<sn << cameraKey;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
bool HSnData::checkCount(int* checkNum)
|
|
{
|
|
bool result = true;
|
|
SNINFO* snInfo = getFristSnInfo();
|
|
if (snInfo == nullptr)
|
|
return result;
|
|
QMutexLocker locker(m_mutex);
|
|
QMap<QString, int> dst_camreaIndexMap = snInfo->getcamreaIndexMap();
|
|
QStringList keyList = dst_camreaIndexMap.keys();
|
|
|
|
for (int i = 0; i < keyList.size(); i++)
|
|
{
|
|
if (snInfo->getcamreaIndexMapValue(keyList[i]) != camreaPicNumMap.value(keyList[i]))
|
|
{
|
|
|
|
result= false;
|
|
}
|
|
|
|
}
|
|
delete[]checkNum;
|
|
checkNum = nullptr;
|
|
return result;
|
|
}
|
|
|
|
bool HSnData::checkCount(int* checkNum, QString station)
|
|
{
|
|
bool result = true;
|
|
SNINFO* snInfo = getFristSnInfo();
|
|
if (snInfo == nullptr)
|
|
return result;
|
|
QMutexLocker locker(m_mutex);
|
|
QMap<QString, int> dst_camreaIndexMap = snInfo->getcamreaIndexMap();
|
|
QStringList keyList = dst_camreaIndexMap.keys();
|
|
|
|
for (int i = 0; i < keyList.size(); i++)
|
|
{
|
|
HCameraData* cameraPtr = station_list.value(station)->getCameraData(keyList[i]);
|
|
if (cameraPtr->GetMatNum() != camreaPicNumMap.value(keyList[i]))
|
|
{
|
|
qDebug() <<"cameraKey:" << keyList[i] <<"cameraPicMax:"<< camreaPicNumMap.value(keyList[i]) << " cameraPtr->GetMatNum():" << cameraPtr->GetMatNum();
|
|
int count = camreaPicNumMap.value(keyList[i]) - cameraPtr->GetMatNum();
|
|
qDebug() << "snImage loss,add " << count << " pics";
|
|
for (int m = 0; m < count; m++)
|
|
{
|
|
HCameraData* cameraPtr = station_list.value(station)->getCameraData(keyList[i]);
|
|
if (cameraPtr)
|
|
{
|
|
std::vector<cv::Mat> camera_mat;
|
|
camera_mat.push_back(cv::Mat(0, 0, CV_8UC1).setTo(0));
|
|
camera_mat.push_back(cv::Mat(0, 0, CV_8UC1).setTo(0));
|
|
cameraPtr->addImageData(camera_mat);
|
|
camera_mat.clear();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
delete[]checkNum;
|
|
checkNum = nullptr;
|
|
return result;
|
|
}
|
|
|
|
bool HSnData::waitSnOver(int* checkNum, QString station)
|
|
{
|
|
bool result = true;
|
|
SNINFO* snInfo = getFristSnInfo();
|
|
if (snInfo == nullptr)
|
|
return result;
|
|
QMutexLocker locker(m_mutex);
|
|
QMap<QString, int> dst_camreaIndexMap = snInfo->getcamreaIndexMap();
|
|
QStringList keyList = dst_camreaIndexMap.keys();
|
|
|
|
for (int i = 0; i < keyList.size(); i++)
|
|
{
|
|
HCameraData* cameraPtr = station_list.value(station)->getCameraData(keyList[i]);
|
|
if (cameraPtr->GetMatNum() != camreaPicNumMap.value(keyList[i]))
|
|
{
|
|
qDebug() << "cameraKey:" << keyList[i] << "cameraPicMax:" << camreaPicNumMap.value(keyList[i]) << " cameraPtr->GetMatNum():" << cameraPtr->GetMatNum();
|
|
result = false;
|
|
}
|
|
|
|
}
|
|
delete[]checkNum;
|
|
checkNum = nullptr;
|
|
return result;
|
|
}
|
|
|
|
bool HSnData::setCount(int* Num)
|
|
{
|
|
SNINFO* snInfo = getFristSnInfo();
|
|
QMap<QString, int> dst_camreaIndexMap = snInfo->getcamreaIndexMap();
|
|
QStringList keyList = dst_camreaIndexMap.keys();
|
|
|
|
for (int i = 0; i < keyList.size(); i++)
|
|
{
|
|
snInfo->updatecamreaIndexMap(keyList[i], *Num);
|
|
Num++;
|
|
}
|
|
//delete[]Num;
|
|
return true;
|
|
}
|
|
|
|
SNINFO* HSnData::getFristSnInfo()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
if (sninfo_list.size() > 0)
|
|
return sninfo_list.first();
|
|
else
|
|
return nullptr;
|
|
}
|
|
|
|
void HSnData::removeOne()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
if (sninfo_list.size() > 0) {
|
|
SNINFO* sninfo = sninfo_list.at(0);
|
|
sninfo_list.removeAt(0);
|
|
delete sninfo;
|
|
sninfo = nullptr;
|
|
}
|
|
|
|
}
|
|
|
|
void HSnData::removeSn(int* checkNum)
|
|
{
|
|
while (true)
|
|
{
|
|
SNINFO* snInfo = getFristSnInfo();
|
|
if (snInfo == nullptr)
|
|
break;
|
|
QMutexLocker locker(m_mutex);
|
|
bool result = true;
|
|
QMap<QString, int> dst_camreaIndexMap = snInfo->getcamreaIndexMap();
|
|
QStringList keyList = dst_camreaIndexMap.keys();
|
|
|
|
for (int i = 0; i < keyList.size(); i++)
|
|
{
|
|
if (snInfo->getcamreaIndexMapValue(keyList[i]) != camreaPicNumMap.value(keyList[i]))
|
|
{
|
|
result = false;
|
|
}
|
|
}
|
|
if (result)
|
|
{
|
|
sninfo_list.removeAt(0);
|
|
delete snInfo;
|
|
snInfo = nullptr;
|
|
qDebug() << "delete an old sn";
|
|
}
|
|
else
|
|
break;
|
|
}
|
|
delete[]checkNum;
|
|
checkNum = nullptr;
|
|
return ;
|
|
|
|
}
|
|
|
|
int HSnData::snInfoSize()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
return sninfo_list.size();
|
|
}
|
|
|
|
bool HSnData::checkSn(QString sn1, QString sn2)
|
|
{
|
|
bool checkResult = false;
|
|
|
|
if (sn1 == "NG" || sn2 == "NG")
|
|
return checkResult;
|
|
|
|
for (int i = 0; i < sninfo_list.size(); i++)
|
|
{
|
|
if (sninfo_list[i]->sn1 == sn1 && sninfo_list[i]->sn2 == sn2)//产品连续NG会导致拍照跳出,PLC卡停
|
|
{
|
|
checkResult = true;
|
|
break;
|
|
}
|
|
}
|
|
return checkResult;
|
|
}
|
|
|
|
void HSnData::clearData()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
sninfo_list.clear();
|
|
}
|
|
|
|
void HSnData::setcamreaPicNumMap(QMap<QString, int> m_camreaPicNumMap)
|
|
{
|
|
camreaPicNumMap = m_camreaPicNumMap;
|
|
camreaPicNumMap.detach();
|
|
}
|
|
|
|
void HSnData::setcameraProductSurface(QMap<QString, QVector<QString>> m_cameraProductSurfaceMap)
|
|
{
|
|
cameraProductSurfaceMap = m_cameraProductSurfaceMap;
|
|
cameraProductSurfaceMap.detach();
|
|
}
|
|
|
|
QString HSnData::getcameraProductSurface(QString cameraKey, int index)
|
|
{
|
|
QVector<QString> valueVec = cameraProductSurfaceMap.value(cameraKey);
|
|
if (valueVec.size() > index)
|
|
return valueVec.at(index);
|
|
else
|
|
return "";
|
|
}
|
|
|
|
// 存储算法结果的数据
|
|
HAlgorithmData::HAlgorithmData()
|
|
{
|
|
m_mutex = new QMutex;
|
|
}
|
|
|
|
HAlgorithmData::~HAlgorithmData()
|
|
{
|
|
if(m_mutex)
|
|
{
|
|
delete m_mutex;
|
|
m_mutex = nullptr;
|
|
}
|
|
}
|
|
|
|
void HAlgorithmData::setDeleteResultMap(QMap<QString, Algorithm_Result_Data_index> map)
|
|
{
|
|
map_delete_Result_index = map;
|
|
}
|
|
|
|
QByteArray HAlgorithmData::getAlgorithmData(QString cameraName_and_index,QString algorithm_result_index)
|
|
{
|
|
QByteArray result_byte;
|
|
QMutexLocker locker(m_mutex);
|
|
|
|
if ( map_algorithm_resultData.keys().contains(cameraName_and_index) )
|
|
{
|
|
return getIndexData(cameraName_and_index,map_algorithm_resultData.value(cameraName_and_index),algorithm_result_index);
|
|
}
|
|
else
|
|
return result_byte;
|
|
}
|
|
|
|
QByteArray HAlgorithmData::getIndexData ( QString cameraName_and_index,Algorithm_Result_Data result_data,QString algorithm_result_index)
|
|
{
|
|
//qDebug() << __FUNCTION__ << " line: " << __LINE__ << " algorithmKey:" << algorithmKey << " cameraName_and_index: " << cameraName_and_index << " result_data.byte len:" << result_data.byte.length();
|
|
|
|
QByteArray index_byte;
|
|
QStringList list = cameraName_and_index.split("_");
|
|
if ( list.size() != 2 )
|
|
{
|
|
qCritical() << "[Error] " << " check list value is error! list len:" << list.length();
|
|
return "";
|
|
}
|
|
|
|
// 删除map中的数据
|
|
map_algorithm_resultData.remove(cameraName_and_index);
|
|
|
|
QString cameraName = list.at(0);
|
|
QString task_index = list.at(1);
|
|
QByteArray byte = result_data.byte;
|
|
|
|
QVector<QString> vec_Data;
|
|
while ( !byte.isEmpty() )
|
|
{
|
|
int type = 0;
|
|
QByteArray m_type = byte.mid(0,4);
|
|
memcpy((void*)&type,(void*)m_type.data(), 4);
|
|
byte.remove(0,4);
|
|
|
|
int len = 0;
|
|
QByteArray m_len = byte.mid(0,4);
|
|
memcpy((void*)&len,(void*)m_len.data(), 4);
|
|
byte.remove(0,4);
|
|
|
|
QByteArray m_data = byte.mid(0,len);
|
|
vec_Data.append(QString(m_data));
|
|
byte.remove(0,len);
|
|
}
|
|
|
|
if ( vec_Data.size() < algorithm_result_index.toInt() )
|
|
{
|
|
qCritical() << "[Error] " << " algorithmKey:" << algorithmKey << " get Index Data is error!";
|
|
return index_byte;
|
|
}
|
|
|
|
QString m_data = vec_Data.at(algorithm_result_index.toInt());
|
|
|
|
std::string sendMsg;
|
|
// type
|
|
int type = 3;
|
|
std::string m_type;
|
|
m_type.insert(0, 4, '1');
|
|
memcpy((void*)m_type.c_str(), (void*)&type, 4);
|
|
sendMsg.append(m_type);
|
|
|
|
// len
|
|
int len = m_data.toStdString().length();
|
|
std::string m_len;
|
|
m_len.insert(0, 4, '1');
|
|
memcpy((void*)m_len.c_str(), (void*)&len, 4);
|
|
sendMsg.append(m_len);
|
|
|
|
// data x
|
|
sendMsg.append(m_data.toStdString());
|
|
|
|
index_byte = QByteArray::fromStdString(sendMsg);
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " algorithmKey:" << algorithmKey << " index_byte len: " << index_byte.length();
|
|
return index_byte;
|
|
}
|
|
|
|
void HAlgorithmData::clearData()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
map_algorithm_resultData.clear();
|
|
}
|
|
|
|
bool HAlgorithmData::checkAlgorithmData( QString cameraName_and_index )
|
|
{
|
|
if ( map_algorithm_resultData.keys().contains(cameraName_and_index))
|
|
{
|
|
return true;
|
|
}
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " algorithmKey:" << algorithmKey << " algorithmData len:" << algorithmData.length();
|
|
return false;;
|
|
}
|
|
|
|
void HAlgorithmData::addAlgorithmData( QString cameraName_and_index,Algorithm_Result_Data result_data )
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
map_algorithm_resultData.insert(cameraName_and_index,result_data);
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " algorithmKey:"<< algorithmKey << " cameraName_and_index:" << cameraName_and_index ;
|
|
}
|
|
|
|
/********************************/
|
|
HAlgorithmExecData::HAlgorithmExecData()
|
|
{
|
|
m_mutex = new QMutex;
|
|
}
|
|
|
|
HAlgorithmExecData::~HAlgorithmExecData()
|
|
{
|
|
if(m_mutex)
|
|
{
|
|
delete m_mutex;
|
|
m_mutex = nullptr;
|
|
}
|
|
}
|
|
|
|
bool HAlgorithmExecData::getDetectData(testData& picVec)
|
|
{
|
|
bool result = true;
|
|
if(!m_detectData.isEmpty())
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
testData picVec1 = m_detectData.head();
|
|
picVec.cameraName = picVec1.cameraName; // 提取名称
|
|
picVec.task_index = picVec1.task_index; // 任务下标
|
|
picVec.byte = picVec1.byte;
|
|
picVec.dstImageMat.assign(picVec1.dstImageMat.begin(),picVec1.dstImageMat.end());
|
|
}
|
|
else
|
|
result = false;
|
|
|
|
return result;
|
|
}
|
|
|
|
bool HAlgorithmExecData::deleteDetectData()
|
|
{
|
|
bool result = false;
|
|
|
|
QMutexLocker locker(m_mutex);
|
|
if(!m_detectData.isEmpty())
|
|
{
|
|
m_detectData.dequeue();
|
|
result = true;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void HAlgorithmExecData::addDetectData(testData detectData)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
m_detectData.append(detectData);
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " algorithmName: " << algorithmName << " m_detectData len:" << m_detectData.length();
|
|
}
|
|
|
|
void HAlgorithmExecData::clearData()
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
m_detectData.clear();
|
|
}
|
|
|
|
|
|
/*********************************/
|
|
HStationData::HStationData()
|
|
{
|
|
|
|
}
|
|
|
|
HStationData::~HStationData()
|
|
{
|
|
foreach(HCameraData *ptr,camera_list_Ptr)
|
|
{
|
|
if(ptr)
|
|
{
|
|
delete ptr;
|
|
ptr = nullptr;
|
|
}
|
|
}
|
|
qDebug() << "[INFO] " << " ~HStationData success!";
|
|
}
|
|
|
|
bool HStationData::checkCameraData(QString cameraKey,QString index)
|
|
{
|
|
HCameraData *camera_ptr = nullptr;
|
|
foreach ( HCameraData *ptr,camera_list_Ptr )
|
|
{
|
|
if ( ptr->getCameraKey() == cameraKey )
|
|
{
|
|
camera_ptr = ptr;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ( camera_ptr )
|
|
{
|
|
if ( camera_ptr->checkImageData(index) )
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// 获取相机数据
|
|
HCameraData* HStationData::getCameraData(QString cameraKey)
|
|
{
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " cameraKey:" << cameraKey;
|
|
foreach ( HCameraData *ptr,camera_list_Ptr )
|
|
{
|
|
if(ptr->getCameraKey() == cameraKey)
|
|
return ptr;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
// 添加相机数据
|
|
void HStationData::addCameraData(HCameraData *cameraData)
|
|
{
|
|
camera_list_Ptr.append(cameraData);
|
|
}
|
|
|
|
|
|
// 添加算法数据
|
|
void HStationData::addAlgorithmData(HAlgorithmData* algorithmData)
|
|
{
|
|
algotithmlist_Ptr.append(algorithmData);
|
|
// qDebug() << __FUNCTION__ << " line:" << __LINE__ << " algotithmlist_Ptr len:" << algotithmlist_Ptr.length();
|
|
}
|
|
|
|
// 获取 算法指针
|
|
HAlgorithmData* HStationData::getAlgorithmData( QString algorithmKey )
|
|
{
|
|
foreach ( HAlgorithmData *ptr,algotithmlist_Ptr )
|
|
{
|
|
if ( ptr->getAlgorithmKey() == algorithmKey )
|
|
return ptr;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
bool HStationData::checkAlgorithmResultData(QString algorithmKey,QString index)
|
|
{
|
|
HAlgorithmData *algorithm_ptr = nullptr;
|
|
foreach ( HAlgorithmData *m_ptr,algotithmlist_Ptr )
|
|
{
|
|
if ( m_ptr->getAlgorithmKey() == algorithmKey )
|
|
{
|
|
algorithm_ptr = m_ptr;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if ( algorithm_ptr )
|
|
{
|
|
if ( algorithm_ptr->checkAlgorithmData(index) )
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**************************************/
|
|
|
|
void HStationData::addAlgorithmExecData(HAlgorithmExecData* algorithmData)
|
|
{
|
|
algotithmExecList_Ptr.append(algorithmData);
|
|
//qDebug() << __FUNCTION__ << " line:" << __LINE__ << " algotithmlist_Ptr len:" << algotithmlist_Ptr.length();
|
|
}
|
|
|
|
void HStationData::clearData()
|
|
{
|
|
for (int i = 0; i < camera_list_Ptr.size(); i++)
|
|
camera_list_Ptr[i]->clearData();
|
|
|
|
if(m_snData != nullptr)
|
|
m_snData->clearData();
|
|
|
|
for (int i = 0; i < algotithmExecList_Ptr.size(); i++)
|
|
algotithmExecList_Ptr[i]->clearData();
|
|
|
|
for (int i = 0; i < algotithmlist_Ptr.size(); i++)
|
|
algotithmlist_Ptr[i]->clearData();
|
|
}
|
|
|
|
|
|
HAlgorithmExecData* HStationData::getAlgorithmExecData( QString algorithmKey )
|
|
{
|
|
foreach ( HAlgorithmExecData *ptr,algotithmExecList_Ptr )
|
|
{
|
|
if ( ptr->getAlgorithmName() == algorithmKey )
|
|
return ptr;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void SNINFO::setcamreaIndexMap(QMap<QString, int> m_camreaIndexMap)
|
|
{
|
|
camreaIndexMap = m_camreaIndexMap;
|
|
camreaIndexMap.detach();
|
|
}
|
|
|
|
QMap<QString, int> SNINFO::getcamreaIndexMap()
|
|
{
|
|
//qDebug() << "size:" << camreaIndexMap.size();
|
|
return camreaIndexMap;
|
|
}
|
|
|
|
void SNINFO::updatecamreaIndexMap(QString cameraKey, int value)
|
|
{
|
|
camreaIndexMap.insert(cameraKey, value);
|
|
}
|
|
|
|
int SNINFO::getcamreaIndexMapValue(QString cameraKey)
|
|
{
|
|
return camreaIndexMap.value(cameraKey);
|
|
}
|
|
|
|
ResultSnData::ResultSnData()
|
|
{
|
|
m_mutex = new QMutex();
|
|
}
|
|
|
|
void ResultSnData::addResultSnInfo(resultSnInfo* snInfo)
|
|
{
|
|
QMutexLocker locker(m_mutex);
|
|
resultSnInfo_list.push_back(snInfo);
|
|
}
|
|
|
|
resultSnInfo* ResultSnData::getResultSnInfo()
|
|
{
|
|
resultSnInfo* info = nullptr;
|
|
QMutexLocker locker(m_mutex);
|
|
if (resultSnInfo_list.size() > 0)
|
|
{
|
|
info = resultSnInfo_list.at(0);
|
|
resultSnInfo_list.removeAt(0);
|
|
}
|
|
return info;
|
|
}
|