基础代码更新

This commit is contained in:
rci
2024-09-27 15:54:51 +08:00
parent 845c8f3e7f
commit 4837ca2bde
293 changed files with 320 additions and 79155 deletions
@@ -1,20 +1,6 @@
#include "Logic_camera_thread.h"
#include "Logic_camera_thread.h"
//QMap<QString, bool> Logic_camera_thread::Map_getImageflag;
//获取时间字符串
std::string getCurrentDateTime_2() {
// 获取当前时间点
auto now = std::chrono::system_clock::now();
// 转换为字符串
auto currentTime = std::chrono::system_clock::to_time_t(now);
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
std::tm* localTime = std::localtime(&currentTime);
std::stringstream ss;
ss << std::put_time(localTime, "%H-%M-%S") << "-" << std::setfill('0') << std::setw(3) << ms.count();
return ss.str();
}
void Logic_camera_thread::adddataIntegrationThread(Logic_hdataintegration* mythread)
{
mydataIntegrationThread.enqueue( mythread);
@@ -90,7 +76,6 @@ void Logic_camera_thread::set_m_stoprun(bool val)
QMutexLocker locker(ifMissImage_mutex); // 加锁
m_stoprun = val;
}
clock_t maxTime_start, maxTime_stop;
void Logic_camera_thread::run()
{
while (ifRun)
@@ -101,7 +86,7 @@ void Logic_camera_thread::run()
m_stoprun = false;
getImg_faileNums = 0;
ifsaveImage = false;
set_ifMissImage(false);
//set_ifMissImage(false);
cu_runNum = 0;
int last_addImageNums = addImageNums;
maxTime_start = clock();
@@ -124,7 +109,7 @@ void Logic_camera_thread::run()
{
qCritical() << __FUNCTION__ << " line:" << __LINE__ << "maxTime_stop - maxTime_start > maxCheckTime! " << m_Module.module_key;
std::cout << "maxTime_stop - maxTime_start > maxCheckTime! " << m_Module.module_key.toStdString() << std::endl;
break;
//break;
}
}
@@ -260,12 +245,12 @@ bool Logic_camera_thread::runCameraModule()
}
//int de = camera_mat[0].rows * camera_mat[0].cols * camera_mat[0].channels() * camera_mat[0].depth() / 8;
//图像检查
for (int i = 0; i < camera_mat.size(); i++)
if ((camera_mat[i].dataend - camera_mat[i].datastart) < camera_mat[i].rows * camera_mat[i].cols * camera_mat[i].channels()) //尝试能否解决mtx内容异常问题
{
camera_mat[i] = cv::Mat::zeros(camera_mat[i].rows, camera_mat[i].cols, camera_mat[i].type());
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " camera_mat[i] data err! zeros";
}
//for (int i = 0; i < camera_mat.size(); i++)
// if ((camera_mat[i].dataend - camera_mat[i].datastart) < camera_mat[i].rows * camera_mat[i].cols * camera_mat[i].channels()) //尝试能否解决mtx内容异常问题
// {
// camera_mat[i] = cv::Mat::zeros(camera_mat[i].rows, camera_mat[i].cols, camera_mat[i].type());
// qCritical() << __FUNCTION__ << " line:" << __LINE__ << " camera_mat[i] data err! zeros";
// }
//保存图片到容器,并运行对应的条件判断
saveImage(camera_mat); //最大耗时30-40ms;
@@ -287,12 +272,12 @@ bool Logic_camera_thread::runCameraModule()
if (CommunicationProcessLevel == 2)
{
maxTime_stop = clock();
if (maxTime_stop - maxTime_start > maxCheckTime)
/*if (maxTime_stop - maxTime_start > maxCheckTime)
{
qCritical() << __FUNCTION__ << " line:" << __LINE__ << "maxCheckTime! hardware" << m_Module.module_key;
std::cout << " maxCheckTime! " << m_Module.module_key.toStdString() << std::endl;
return true;
}
}*/
}
if (!ifRun || m_stoprun == true)
{
@@ -300,47 +285,69 @@ bool Logic_camera_thread::runCameraModule()
return true;
}
QMutexLocker locker(ifMissImage_mutex); // 加锁
//QMutexLocker locker(ifMissImage_mutex); // 加锁
QByteArray task_name;
std::vector<cv::Mat> camera_mat;
if (m_Module.module_ptr->run())
if (CommunicationProcessLevel == 2 && waitenum++%100==0)
{
if (!m_Module.module_ptr->readData(camera_mat, task_name))
{
Sleep(10);
qApp->processEvents();
myTime += 10;
if (myTime*10 > getImgTimeout)
{
if (CommunicationProcessLevel == 2)
{
missImgae_addImage(camera_mat);
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " m_name:" << m_name << " get image is getImgTimeout failed!";
}
}
else continue;
}
//missImgae_addImage(camera_mat);
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " m_name:" << m_name << " waite trigger!"<< waitenum;
}
if (CommunicationProcessLevel == 2 && maxTime_stop - maxTime_start > maxCheckTime)
{
qCritical() << __FUNCTION__ << " line:" << __LINE__ << "maxCheckTime! add img, hardware" << m_Module.module_key;
missImgae_addImage(camera_mat);
}
else
{
if (CommunicationProcessLevel == 2)
if (m_Module.module_ptr->run())
{
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " m_name:" << m_name << " get image is error failed!";
missImgae_addImage(camera_mat);
if (!m_Module.module_ptr->readData(camera_mat, task_name))
{
Sleep(10);
qApp->processEvents();
myTime += 10;
if (myTime % 1000 == 0)
{
if (CommunicationProcessLevel == 2)
{
//missImgae_addImage(camera_mat);
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " m_name:" << m_name << " waite trigger!";
}
}
if (myTime > maxCheckTime)
{
if (CommunicationProcessLevel == 2)
{
missImgae_addImage(camera_mat);
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " m_name:" << m_name << " get image is getImgTimeout failed!";
}
}
else continue;
}
}
/*else
{
if (CommunicationProcessLevel == 2)
{
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " m_name:" << m_name << " get image is error failed!";
missImgae_addImage(camera_mat);
}
}*/
}
if (camera_mat.empty())
{
Sleep(2);
continue;
}
//图像检查
for (int i = 0; i < camera_mat.size(); i++)
if ((camera_mat[i].dataend - camera_mat[i].datastart) < camera_mat[i].rows * camera_mat[i].cols * camera_mat[i].channels()) //尝试能否解决mtx内容异常问题;camera_mat[i].depth()不是8的倍数
{
camera_mat[i] = cv::Mat::zeros(camera_mat[i].rows, camera_mat[i].cols, camera_mat[i].type());
qCritical() << __FUNCTION__ << " line:" << __LINE__ << " camera_mat[i] data err! zeros";
}
////图像检查
//for (int i = 0; i < camera_mat.size(); i++)
// if ((camera_mat[i].dataend - camera_mat[i].datastart) < camera_mat[i].rows * camera_mat[i].cols * camera_mat[i].channels()) //尝试能否解决mtx内容异常问题;camera_mat[i].depth()不是8的倍数
// {
// camera_mat[i] = cv::Mat::zeros(camera_mat[i].rows, camera_mat[i].cols, camera_mat[i].type());
// qCritical() << __FUNCTION__ << " line:" << __LINE__ << " camera_mat[i] data err! zeros";
// }
//保存图片到容器,并运行对应的条件判断
saveImage(camera_mat);
@@ -365,10 +372,6 @@ bool Logic_camera_thread::runCameraModule()
//保存图片到容器,并运行对应的条件判断
bool Logic_camera_thread::saveImage(std::vector<cv::Mat> camera_mat)
{
////// 保存图片文件夹
QString Qpath = m_saveImage;
clock_t start, stop;
start = clock();
HCameraData *cameraPtr = station_list.value(m_stationName)->getCameraData(m_name);
@@ -380,14 +383,6 @@ bool Logic_camera_thread::saveImage(std::vector<cv::Mat> camera_mat)
QVector<QString> vector_sn = getSnData(camera_index);
QString channel_index = nullptr;
//还缺时间加白夜班和SN码
std::string Path;
Path = Qpath.toLocal8Bit();
std::string SPath = std::string(Path);
cv::imwrite(SPath + "\\" + "0.bmp", camera_mat[0]);
//拍照面描述
QString Surface;
if(cameraProductSurface.size()>0)