相机模块待完善

This commit is contained in:
2024-05-21 18:11:13 +08:00
parent b39487a39f
commit cb681bd97a
29 changed files with 260 additions and 330 deletions
@@ -33,37 +33,6 @@ std::string getCurrentDateTime_2() {
}
int threadAmount = 0;
int maxThread = 16;
/// <summary>
/// 获取当前时间点,以"小时-分钟-秒"返回
/// </summary>
/// <returns></returns>
std::string getCurrentDateTime() {
// 获取当前时间点
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
// 转换为字符串
std::time_t currentTime = std::chrono::system_clock::to_time_t(now);
std::tm* localTime = std::localtime(&currentTime);
std::stringstream ss;
ss << std::put_time(localTime, "%H-%M-%S");
return ss.str();
}
/// <summary>
/// 检查目标文件夹是否存在,不存在则创建
/// </summary>
/// <param name="path"></param>
void createDirectoryIfNotExists(const std::string& path) {
// 检查路径是否存在
if (!std::filesystem::exists(path)) {
// 创建路径
std::filesystem::create_directories(path);
//std::cout << "已创建文件夹: " << path << std::endl;
}
else {/*
std::cout << "文件夹已存在: " << path << std::endl;*/
}
}
////////////THREAD//CONTROLLER////////////////////////
threadConroller::threadConroller(QObject* parent) : QThread(parent)
@@ -72,10 +41,10 @@ threadConroller::threadConroller(QObject* parent) : QThread(parent)
sql = new sqlController;
sql->initPara();
//辅助线程初始化
oriSaveThread->oriThread = true;
oriSaveThread->Init(this);
//oriSaveThread->oriThread = true;
//oriSaveThread->Init(this);
resSaveThread->Init(this);
//resSaveThread->Init(this);
threadAmount = bridge.back.json.algoThreads.algoDataMap.size();
for (int i = 0; i < threadAmount; i++)
{
@@ -215,135 +184,6 @@ threadConroller::~threadConroller()
delete thread;
}
}
////////////////SUBTHREAD////////////////////////
bool folderExists(const std::string& folderPath) {
return std::filesystem::is_directory(folderPath);
}
void imgSaveThread::Init(threadConroller* tC)
{
sql = tC->sql;
snDatas = &tC->snDatas;
}
void imgSaveThread::saveOriginalImg(imgSaveStruct& data)
{
//根据时间获取大概路径
sqlTableDatas sqlRes = sql->selectSingleData("saveHour", data.SNcode);//查找之前的数据
std::string fileSavePath = bridge.back.json.imgSavePath.toStdString();
if (sqlRes.rowDatas.size() > 0 && sqlRes.rowDatas[0][0].value != "")//数据存在
{
fileSavePath += "//yuantu//" + sqlRes.tableName + "//" + sqlRes.rowDatas[0][0].value + "H//";
}
else//数据不存在 新建数据
{
QDateTime currentDateTime = QDateTime::currentDateTime();
std::string ymd = currentDateTime.toString("yyyy-MM-dd").toStdString();
int h = currentDateTime.time().hour();
fileSavePath += "//yuantu//" + ymd + "//" + to_string(h) + "H//";
sql->addData(data.SNcode, { { "saveHour",to_string(h) } });
}
if ((data.SNcode).length() != 0)
fileSavePath += data.SNcode + "//";
else
fileSavePath += "camera_" + data.cameraKeyName + "//";
createDirectoryIfNotExists_2(fileSavePath);//文件夹处理
std::string fileName;
//while (folderExists(resPath) != true);
////////////////
if (data.cameraKeyName.find("3D") != -1 && data.imgs.size() == 2)
{
fileName = data.cameraKeyName + "-" + "_time" + getCurrentDateTime_2();
cv::imwrite(fileSavePath + fileName + ".bmp", data.imgs[0]);
cv::imwrite(fileSavePath + fileName + ".tiff", data.imgs[1]);
}
else
{
std::string fileName;
data.cameraKeyName;
for (int i = 0; i < data.imgs.size(); i++)
{
fileName = data.cameraKeyName + "-" + to_string(i) + "_time" + getCurrentDateTime_2() + ".bmp";
cv::imwrite(fileSavePath + fileName, data.imgs[i]);
qDebug() << "[Debug]" << QString::fromStdString(data.cameraKeyName + " res:" + fileSavePath + fileName);
//cout << resPath << fileName << endl;
}
}
return;
}
void imgSaveThread::saveResultImg(imgSaveStruct& data)
{
try
{
//根据时间获取大概路径
sqlTableDatas sqlRes = sql->selectSingleData("saveHour", data.SNcode);//查找之前的数据
std::string fileSavePath = bridge.back.json.imgSavePath.toStdString();
if (sqlRes.rowDatas.size() > 0 && sqlRes.rowDatas[0][0].value != "")//数据存在
{
fileSavePath += "//result//" + sqlRes.tableName + "//" + sqlRes.rowDatas[0][0].value + "H//";
}
else//数据不存在 新建数据
{
QDateTime currentDateTime = QDateTime::currentDateTime();
std::string ymd = currentDateTime.toString("yyyy-MM-dd").toStdString();
int h = currentDateTime.time().hour();
fileSavePath += "//result//" + ymd + "//" + to_string(h) + "H//";
sql->addData(data.SNcode, { { "saveHour",to_string(h) } });
}
//有SN码就储存在SN码路径,无则储存在相机路径
if ((data.SNcode).length() != 0)
fileSavePath += data.SNcode + "//";
else
fileSavePath += "camera_" + data.cameraKeyName + "//";
createDirectoryIfNotExists_2(fileSavePath);//文件夹处理
std::string fileName;
//while (folderExists(resPath) != true);
//else
{
for (int i = 0; i < data.imgs.size(); i++)
{
fileName = data.cameraKeyName + "_" + getCurrentDateTime_2() + "_time" + to_string(i) + ".jpg";
cv::imwrite(fileSavePath + fileName, data.imgs[i]);
qDebug() << "[Debug]" << QString::fromStdString(data.cameraKeyName + " ori:" + fileSavePath + fileName);
}
}
}
catch (...)
{
return;
}
}
void imgSaveThread::run()
{
if (oriThread == false)
while (m_runFlag == true)
{
while (resQueue.size() > 0)
{
resMutex.lock();
imgSaveStruct data = resQueue.dequeue();
resMutex.unlock();
saveResultImg(data);
}
QThread::msleep(10);
}
else
while (m_runFlag == true)
{
while (oriQueue.size() > 0)
{
oriMutex.lock();
imgSaveStruct data = oriQueue.dequeue();
oriMutex.unlock();
saveOriginalImg(data);
}
QThread::msleep(10);
}
}
////////////////DET//DATA//////////////////
sncodeCls::sncodeCls()
{