进行部分代码更新以及修改传输数据功能

main
seiyu 1 year ago
parent dfacffd891
commit ed9c76f165

@ -133,7 +133,7 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp14</LanguageStandard>
<Optimization>MaxSpeed</Optimization>
<Optimization>Disabled</Optimization>
<SupportJustMyCode>false</SupportJustMyCode>
<DisableSpecificWarnings>4819;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
@ -141,7 +141,7 @@
<SubSystem>Console</SubSystem>
<OutputFile>$(OutDir)\$(ProjectName).exe</OutputFile>
<AdditionalLibraryDirectories>$(QTDIR)\lib;$(ProjectDir)OpenCV455Simple\win64\vc15\lib;$(ProjectDir)Pylon6.2\lib\Win64;$(ProjectDir)MvIMPACT\lib\win64;$(ProjectDir)MVS3.2.1\lib\win64;$(ProjectDir)modbus;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>qtmain.lib;Qt5Core.lib;Qt5Widgets.lib;Qt5Gui.lib;opencv_world455.lib;modbus.lib;mvDeviceManager.lib;MvCameraControl.lib;Qt5Network.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>
</IgnoreSpecificDefaultLibraries>

@ -64,8 +64,8 @@ void CleanWorkThread::doWork()
GetDiskFreeSpaceEx(strDriver, &freeDiskSpaceAvailable, &totalDiskSpace, &totalFreeDiskSpace);
spaceSize = ((qint64)totalFreeDiskSpace.QuadPart * (100/freeSize)) / (qint64)totalDiskSpace.QuadPart;
dirSize = DirFileSize(dir) / gb;
delDays = g_sys_conf.save_days;
while ((spaceSize < 1) && (delDays >= 0)) { //磁盘剩余空间小于百分之十
//delDays = g_sys_conf.save_days;
while ((spaceSize < 1) && (delDays > 1)) { //磁盘剩余空间小于百分之十
CleanImageFile(dir, delDays--);
GetDiskFreeSpaceEx(strDriver, &freeDiskSpaceAvailable, &totalDiskSpace, &totalFreeDiskSpace);
spaceSize = ((qint64)totalFreeDiskSpace.QuadPart * (100 / freeSize)) / (qint64)totalDiskSpace.QuadPart;

@ -20,7 +20,7 @@ ConfPath g_conf_path;
SysConf g_sys_conf; //系统配置参数
ModbusConf g_modbus_conf; //modbus地址参数
PLCDevice * m_PLCDevice;
PLCDevice* m_PLCDevice;
bool g_plc_dialog_open; //是否打开plc配置对话框
QDateTime g_ts_start;
@ -1229,7 +1229,7 @@ void Cigarette::OnDBClickNGHub(int Num)
QString file_path = g_conf_path.save_pics_path;
std::replace(file_path.begin(), file_path.end(), '/', '\\');
ostr << "explorer "<< file_path.toLocal8Bit().constData() << "\\ng\\" << (now_ts.toString("yyyy-MM-dd")).toStdString()<< "\\" << Num+1 << "\\" << 1;
ostr << "explorer "<< file_path.toLocal8Bit().constData() << "\\ng\\" << (now_ts.toString("yyyy-MM-dd")).toStdString()<< "\\" << Num+1;
std::string str = ostr.str();
//std::cout << "===>" << str << std::endl;
system(str.c_str());

@ -20,7 +20,7 @@
//#define DOUBLE_FEED_BACK //一次ng两次反馈ng信号
#endif
//#define identify_Hik_YSXID//识别海康相机YSXID
//#define __ExportData // 输出检测数据到XML文档
#define __ExportData // 输出检测数据到XML文档
//#define DRAW_RECT // 鼠标画框功能
#define Queue_Size 15
@ -34,7 +34,7 @@
#endif
// 主界面基本参数配置文件
#define CONFPATH "conf_path.txt"
#define CONFPATH "D:/Release/conf_path.txt"
//#define CONFIGURE_FILE "D:/conf/conf.txt"
// 相机旋转角度配置文件
#define ROTATE_FILE "rotate.txt"

@ -3,28 +3,32 @@
#include "QtCore\qtextstream.h"
#include<string>
Cigarette* cg;
extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue;
extern ConfPath g_conf_path;
ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent)
{
char xmlPath[256];
//char xmlPath[256];
cg->read_conf(g_conf_path);
for (int index = 0; index < NumberOfSupportedCameras; index++)
{
XMLError error;
pDocument[index] = new XMLDocument();
memset(xmlPath, 0, 256);
pDocument[index] = new tinyxml2::XMLDocument();
//memset(xmlPath, 0, 256);
QString xmlPath = QString(EXPORTDATA_FILE).arg(index);
//sprintf(xmlPath, EXPORTDATA_FILE, index);
QString filePath = g_conf_path.config_path + "/" + xmlPath;
error = pDocument[index]->LoadFile(filePath.toStdString().c_str());
error = pDocument[index]->LoadFile(filePath.toLocal8Bit().constData());
if (error != XML_SUCCESS)
{
XMLDeclaration* declaration = pDocument[index]->NewDeclaration();
pDocument[index]->InsertFirstChild(declaration);
XMLElement* root = pDocument[0]->NewElement("Root");
pDocument[0]->InsertEndChild(root);
pDocument[index]->SaveFile(filePath.toStdString().c_str());
pDocument[index]->SaveFile(filePath.toLocal8Bit().constData());
}
/*
_ExportDataInfo data;
@ -33,6 +37,14 @@ ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent)
data.timeCost = "3ms";
insertXMLNode(xmlPath, data);
*/
_XMLExportDataInfo data;
data.cameraId = index;
data.cameraTotal = 3;
data.TotalCheckNum = 1000;
data.TotalKickNum = 900;
data.AcquisitionSpeed = "3ms";
insertXMLNode(filePath.toLocal8Bit().constData(), data);
}
}
@ -55,7 +67,7 @@ void ExportDataThread::stop()
bool _ExportDataInfo::getAverageData(map<string, float> &averageData, int index)
{
XMLDocument doc;
tinyxml2::XMLDocument doc;
//char xmlPath[256];
XMLError error;
map<string, float> data;
@ -63,9 +75,9 @@ bool _ExportDataInfo::getAverageData(map<string, float> &averageData, int index)
QString xmlPath = QString(EXPORTDATA_FILE).arg(index);
//sprintf(xmlPath, EXPORTDATA_FILE, index);
QString filePath = g_conf_path.config_path + "/" + xmlPath;
error = doc.LoadFile(filePath.toStdString().c_str());
error = doc.LoadFile(filePath.toLocal8Bit().constData());
if (error != XML_SUCCESS)
if (doc.LoadFile(filePath.toStdString().c_str()) != 0)
if (doc.LoadFile(filePath.toLocal8Bit().constData()) != 0)
{
cout << "load xml file failed" << endl;
return false;
@ -140,6 +152,49 @@ int ExportDataThread::insertXMLNode(const char* xmlPath, _ExportDataInfo& data)
return pDocument[data.cameraId]->SaveFile(xmlPath);
}
int ExportDataThread::insertXMLNode(const char* xmlPath, _XMLExportDataInfo& data)
{
XMLElement* root = pDocument[data.cameraId]->RootElement();
if (root == NULL) {
root = pDocument[data.cameraId]->NewElement("Root");
pDocument[data.cameraId]->InsertEndChild(root);
pDocument[data.cameraId]->SaveFile(xmlPath);
}
XMLElement* CameraNode = pDocument[data.cameraId]->NewElement("Camera");
CameraNode->SetAttribute("Id", data.cameraId);
CameraNode->SetAttribute("Count ", data.cameraTotal);
root->InsertEndChild(CameraNode);
//XMLElement* IsNG = pDocument[data.cameraId]->NewElement("IsNG");
//XMLText* IsNGText = pDocument[data.cameraId]->NewText(data.isNg ? "TRUE" : "FALSE");
//IsNG->InsertEndChild(IsNGText);
//CameraNode->InsertEndChild(IsNG);
//XMLElement* timeCost = pDocument[data.cameraId]->NewElement("TimeCost");
//timeCost->InsertEndChild(pDocument[data.cameraId]->NewText(data.timeCost.c_str()));
//CameraNode->InsertEndChild(timeCost);
XMLElement* TotalCheckNum = pDocument[data.cameraId]->NewElement("TotalCheckNum");
std::string temp_str = std::to_string(data.TotalCheckNum);
const char* temp_char = temp_str.c_str();
TotalCheckNum->InsertEndChild(pDocument[data.cameraId]->NewText(temp_char));
CameraNode->InsertEndChild(TotalCheckNum);
XMLElement* TotalKickNum = pDocument[data.cameraId]->NewElement("TotalKickNum");
temp_str = std::to_string(data.TotalKickNum);
temp_char = temp_str.c_str();
TotalKickNum->InsertEndChild(pDocument[data.cameraId]->NewText(temp_char));
CameraNode->InsertEndChild(TotalKickNum);
XMLElement* AcquisitionSpeed = pDocument[data.cameraId]->NewElement("AcquisitionSpeed");
AcquisitionSpeed->InsertEndChild(pDocument[data.cameraId]->NewText(data.AcquisitionSpeed.c_str()));
CameraNode->InsertEndChild(AcquisitionSpeed);
return pDocument[data.cameraId]->SaveFile(xmlPath);
}
void ExportDataThread::run()
{
while (!b_quit) {
@ -150,7 +205,7 @@ void ExportDataThread::run()
memset(buf, 0, 256);
QString xmlPath = QString(EXPORTDATA_FILE).arg(element.cameraId);
QString filePath = g_conf_path.config_path + "/" + xmlPath;
sprintf(buf, filePath.toStdString().c_str(), element.cameraId);
sprintf(buf, filePath.toLocal8Bit().constData(), element.cameraId);
insertXMLNode(buf, element);
}
}
@ -173,7 +228,9 @@ void ExportDataThread::check_save_dir(std::string dir_path)
}
if (!b_find)
{
QString dir_str = QString::fromStdString(dir_path);
//QString dir_str = QString::fromStdString(dir_path);
QString dir_str = QString::fromLocal8Bit(QByteArray::fromRawData(dir_path.c_str(), dir_path.size()));
QDir dir;
if (!dir.exists(dir_str))
{

@ -9,11 +9,46 @@
#include "basecamera.h"
#include "tinyxml2.h"
#include "common.h"
#include "cigarette.h"
#define EXPORTDATA_FILE "camera%1_data_info.xml"
using namespace tinyxml2;
class _XMLExportDataInfo {
public:
// 总的统计数据
int TotalCheckNum; // 总检测数量
int TotalKickNum; // 总剔除数量
double PassRate; // 合格率
double KickRate; // 剔除率
// 各相机数据
long long cameraTotal;
int cameraId;
int okNum; // 各相机ok数量
int ngNum; // 各相机ng数量
int kickNum; // 各相机实际剔除数量(单通道剔除时为总剔除数量)
string AcquisitionSpeed; // 各相机采集速度
int jdNum[20]; // 各相机胶点识别个数
string DetectSpeed; // 各相机检测速度
_XMLExportDataInfo() {
// 总的统计数据
TotalCheckNum = 0; // 总检测数量
TotalKickNum = 0; // 总剔除数量
PassRate = 0.0; // 合格率
KickRate = 0.0; // 剔除率
// 各相机数据
cameraId = -1;
okNum = 0; // 各相机ok数量
ngNum = 0; // 各相机ng数量
kickNum = 0; // 各相机实际剔除数量(单通道剔除时为总剔除数量)
AcquisitionSpeed = "0ms"; // 各相机采集速度
for (int i = 0; i < 20; i++) jdNum[i] = 0; // 各相机胶点识别个数
DetectSpeed = "0ms"; // 各相机检测速度
}
};
class _ExportDataInfo
{
struct JdPoint //创建点的数据
@ -77,6 +112,7 @@ public:
void start_work();
void stop();
int insertXMLNode(const char* xmlPath, _ExportDataInfo& data);
int insertXMLNode(const char* xmlPath, _XMLExportDataInfo& data);
protected:
void run();
void check_save_dir(std::string dir_path);

@ -218,13 +218,14 @@ void WorkThread::run()
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + ".jpg";
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
/*m = vec_out[index].clone();
file_name = "D:/image/" +
now_ts.toString("yyyy-MM-dd") +
"/" + QString::number(local_camera_number + 1) +
"/ng_result/" + QString::number(index) + "/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + "_" + QString::number(index) + ".bmp";*/
m = vec_out[index].clone();
file_name = g_conf_path.save_pics_path + "/ng_result/" +
now_ts.toString("yyyy-MM-dd") + "/"
+ QString::number(local_camera_number + 1) + "/" + QString::number(index + 1) + "/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + ".bmp";;
//g_save_queue->put(std::make_pair(file_name.toStdString(), m));
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
}

Loading…
Cancel
Save