Init for Cigarette Shanghai

CigaretteSH
Flamingo 9 months ago
parent ca135833a0
commit 51f65124ab

@ -26,7 +26,7 @@ Global
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
Qt5Version = 5.15.2_msvc2019_64
SolutionGuid = {0AF1A30E-A12C-4014-ACD5-65A1E6D54D46} SolutionGuid = {0AF1A30E-A12C-4014-ACD5-65A1E6D54D46}
Qt5Version = 5.15.2_msvc2019_64
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

@ -40,7 +40,7 @@ inline void FallingGpioEventfunction(MV_EVENT_OUT_INFO* pEventInfo, void* pUser)
image.copyTo(roi); image.copyTo(roi);
} }
#ifdef SYNC_CAMERA #ifdef SYNC_CAMERA
{ {//合并所有相机图片放入队列
std::lock_guard<std::mutex> locker(CaptureThreadHIKptr->p_image_sync_arr->lock); std::lock_guard<std::mutex> locker(CaptureThreadHIKptr->p_image_sync_arr->lock);
CaptureThreadHIKptr->p_image_sync_arr->image_sync_arr.at(CaptureThreadHIKptr->Local_Num) = std::make_pair(unit_count, long_image); CaptureThreadHIKptr->p_image_sync_arr->image_sync_arr.at(CaptureThreadHIKptr->Local_Num) = std::make_pair(unit_count, long_image);
CaptureThreadHIKptr->p_image_sync_arr->collect_cnt++; CaptureThreadHIKptr->p_image_sync_arr->collect_cnt++;
@ -220,7 +220,7 @@ void(*RisingGpioEvent[NumberOfSupportedCameras])(MV_EVENT_OUT_INFO* pEventInfo,
,RisingGpioEvent8 ,RisingGpioEvent8
#endif #endif
}; };
void CaptureThreadHIK::fpsTimeout(void) void CaptureThreadHIK::fpsTimeout(void)//采集速度
{ {
uint64_t delta = m_cntGrabbedImages - m_cntLastGrabbedImages; uint64_t delta = m_cntGrabbedImages - m_cntLastGrabbedImages;
m_cntLastGrabbedImages = m_cntGrabbedImages; m_cntLastGrabbedImages = m_cntGrabbedImages;
@ -286,7 +286,7 @@ void CaptureThreadHIK::process(void)
nDataSize = stIntValue.nCurValue * 3;/// nDataSize = stIntValue.nCurValue * 3;///
MV_CC_StartGrabbing(CamHandle); MV_CC_StartGrabbing(CamHandle);
Ready = true; Ready = true;
while (!boTerminated_) while (!boTerminated_)//循环取流,拍照取图
{ {
//nRet = MV_CC_GetOneFrameTimeout(CamHandle, g_pImage_buf, nDataSize, &stFrameInfo, 200); //nRet = MV_CC_GetOneFrameTimeout(CamHandle, g_pImage_buf, nDataSize, &stFrameInfo, 200);
nRet = MV_CC_GetImageForBGR(CamHandle, g_pImage_buf, nDataSize, &stFrameInfo, 100); nRet = MV_CC_GetImageForBGR(CamHandle, g_pImage_buf, nDataSize, &stFrameInfo, 100);

@ -2,11 +2,11 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup /> <PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QTDIR>D:\Qt\5.15.2\msvc2019_64</QTDIR> <QTDIR>C:\Qt\5.15.2\msvc2019_64</QTDIR>
<LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3bD:\Qt\5.15.2\msvc2019_64\bin%3b$(PATH)</LocalDebuggerEnvironment> <LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3bD:\Qt\5.15.2\msvc2019_64\bin%3b$(PATH)</LocalDebuggerEnvironment>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QTDIR>D:\Qt\5.15.2\msvc2019_64</QTDIR> <QTDIR>C:\Qt\5.15.2\msvc2019_64</QTDIR>
<LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3bD:\Qt\5.15.2\msvc2019_64\bin%3b$(PATH)</LocalDebuggerEnvironment> <LocalDebuggerEnvironment>PATH=$(QTDIR)\bin%3bD:\Qt\5.15.2\msvc2019_64\bin%3b$(PATH)</LocalDebuggerEnvironment>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

@ -117,9 +117,10 @@ bool AlgJd::test_detect_batcht(int shoot)
int AlgJd::detect(cv::Mat& _frame, cv::Mat& out, std::vector<std::pair<int, cv::Rect> >& results) int AlgJd::detect(cv::Mat& _frame, cv::Mat& out, std::vector<std::pair<int, cv::Rect> >& results)
{ {
cv::Mat frame = _frame.clone(); cv::Mat frame = _frame.clone();
cv::Mat image_clone = frame.clone(); //cv::Mat image_clone = frame.clone();
// Process frames. // Process frames.
// Create a 4D blob from a frame. // Create a 4D blob from a frame.
//图像预处理:
cv::Mat blob; cv::Mat blob;
cv::dnn::blobFromImage(frame, blob, 1 / 255.0, cv::Size(inpWidth, inpHeight), cv::Scalar(0, 0, 0), true, false); cv::dnn::blobFromImage(frame, blob, 1 / 255.0, cv::Size(inpWidth, inpHeight), cv::Scalar(0, 0, 0), true, false);

@ -67,6 +67,7 @@ SyncQueue<_UDPSendInfo>* UDP_Info_queue;
#endif #endif
#ifdef __TCPSend #ifdef __TCPSend
SyncQueue<_TCPSendInfo>* TCP_Info_queue; SyncQueue<_TCPSendInfo>* TCP_Info_queue;
#endif #endif
bool flag = false; bool flag = false;
SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue; SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue;
@ -113,7 +114,7 @@ Cigarette::Cigarette(QWidget* parent)
InitPtrMat(); InitPtrMat();
read_conf(g_conf_path); read_conf(g_conf_path);
if (!g_conf_path.config_path.isEmpty()) { if (!g_conf_path.config_path.isEmpty()) {//判断conf路径是否存在 空 isEmpty=1不空 isEmpty=0
// 如果非空 // 如果非空
QDir* dirinfo = new QDir(g_conf_path.config_path); QDir* dirinfo = new QDir(g_conf_path.config_path);
if (!dirinfo->exists()) { if (!dirinfo->exists()) {
@ -127,30 +128,33 @@ Cigarette::Cigarette(QWidget* parent)
g_conf_path.config_path = "D:/conf"; g_conf_path.config_path = "D:/conf";
bool update_rotate = false; bool update_rotate = false;
if (!read_rotate_message()) { if (!read_rotate_message()) {//读取旋转参数
update_rotate = true; update_rotate = true;
} }
QThread* hThread = new QThread(); QThread* hThread = new QThread();//主线程
CLog* clogWorkThread = new CLog(); CLog* clogWorkThread = new CLog();//日志线程
clogWorkThread->moveToThread(hThread); clogWorkThread->moveToThread(hThread);//将日志线程依附到主线程(相当于父类)
connect(this, &Cigarette::destroyed, hThread, &QThread::quit); connect(this, &Cigarette::destroyed, hThread, &QThread::quit);//Cigarette退出系统了或这个类崩溃了清除Qt所有线程
connect(hThread, &QThread::finished, clogWorkThread, &CLog::deleteLater); connect(hThread, &QThread::finished, clogWorkThread, &CLog::deleteLater);//Qt类结束清除日志类
connect(this, &Cigarette::sengMsgToClog, clogWorkThread, &CLog::recMegFromCigarette); connect(this, &Cigarette::sengMsgToClog, clogWorkThread, &CLog::recMegFromCigarette);// sengMsgToClog 写日志的信号recMegFromCigarette 写日志操作
hThread->start(); hThread->start();
emit sengMsgToClog("Application Start."); emit sengMsgToClog("Application Start.");
//初始化队列
//保存队列
g_save_queue = new SyncQueue<std::pair<std::string, cv::Mat>>(Queue_Size); g_save_queue = new SyncQueue<std::pair<std::string, cv::Mat>>(Queue_Size);
g_save_queue->name = "save queue"; g_save_queue->name = "save queue";
#ifdef __UDPSend #ifdef __UDPSend
UDP_Info_queue = new SyncQueue<_UDPSendInfo>(Queue_Size); UDP_Info_queue = new SyncQueue<_UDPSendInfo>(Queue_Size);
UDP_Info_queue->name = "UDP Info queue"; UDP_Info_queue->name = "UDP Info queue";
#endif #endif
//TCP队列
#ifdef __TCPSend #ifdef __TCPSend
TCP_Info_queue = new SyncQueue<_TCPSendInfo>(Queue_Size); TCP_Info_queue = new SyncQueue<_TCPSendInfo>(Queue_Size);
TCP_Info_queue->name = "TCP Info queue"; TCP_Info_queue->name = "TCP Info queue";
#endif #endif
//FTP数据队列
#ifdef __ExportData #ifdef __ExportData
export_XMLData_Info_queue = new SyncQueue<_XMLExportDataInfo>(Queue_Size); export_XMLData_Info_queue = new SyncQueue<_XMLExportDataInfo>(Queue_Size);
export_XMLData_Info_queue->name = "Export Data Info queue"; export_XMLData_Info_queue->name = "Export Data Info queue";
@ -158,6 +162,7 @@ Cigarette::Cigarette(QWidget* parent)
last_shift = 256; last_shift = 256;
work_camera_nums = 0; work_camera_nums = 0;
//相机公共队列(合成图片)
#ifdef SYNC_CAMERA #ifdef SYNC_CAMERA
g_image_sync_queue = new SyncQueue<std::vector<std::pair<int, cv::Mat>>>(Queue_Size); g_image_sync_queue = new SyncQueue<std::vector<std::pair<int, cv::Mat>>>(Queue_Size);
g_image_sync_queue->name = format("sync_image"); g_image_sync_queue->name = format("sync_image");
@ -165,20 +170,26 @@ Cigarette::Cigarette(QWidget* parent)
for (int i = 0; i < NumberOfSupportedCameras; i++) for (int i = 0; i < NumberOfSupportedCameras; i++)
{ {
#ifndef SYNC_CAMERA #ifndef SYNC_CAMERA
//相机单独队列
g_image_queue[i] = new SyncQueue<std::pair<int, cv::Mat> >(Queue_Size); g_image_queue[i] = new SyncQueue<std::pair<int, cv::Mat> >(Queue_Size);
g_image_queue[i]->name = format("image_%d", i); g_image_queue[i]->name = format("image_%d", i);
#endif #endif
//结果队列
g_result_queue[i] = new ASyncQueue<bool>(Queue_Size); g_result_queue[i] = new ASyncQueue<bool>(Queue_Size);
g_result_queue[i]->name = format("result_%d", i); g_result_queue[i]->name = format("result_%d", i);
//结果延后队列
g_result_wait_queue[i] = new ASyncQueue<bool>(Queue_Size); g_result_wait_queue[i] = new ASyncQueue<bool>(Queue_Size);
g_result_wait_queue[i]->name = format("result_wait%d", i); g_result_wait_queue[i]->name = format("result_wait%d", i);
//两个结果队列
g_double_queue[i] = new ASyncQueue<bool>(Queue_Size); g_double_queue[i] = new ASyncQueue<bool>(Queue_Size);
g_double_queue[i]->name = format("double_wait%d", i); g_double_queue[i]->name = format("double_wait%d", i);
//拍照队列
g_shooted_queue[i] = new ASyncQueue<bool>(Queue_Size); g_shooted_queue[i] = new ASyncQueue<bool>(Queue_Size);
g_shooted_queue[i]->name = format("shooted_%d", i); g_shooted_queue[i]->name = format("shooted_%d", i);
//调试队列
g_debug_queue[i] = new SyncQueue<cv::Mat>(Queue_Size); g_debug_queue[i] = new SyncQueue<cv::Mat>(Queue_Size);
g_debug_queue[i]->name = format("debug_%d", i); g_debug_queue[i]->name = format("debug_%d", i);
if (update_rotate) { if (update_rotate) {//未读到旋转参数,进行初始化
rotationAngle[i] = cv::ROTATE_90_COUNTERCLOCKWISE + 1; rotationAngle[i] = cv::ROTATE_90_COUNTERCLOCKWISE + 1;
isNeedRotate[i] = false; isNeedRotate[i] = false;
} }
@ -196,7 +207,7 @@ Cigarette::Cigarette(QWidget* parent)
g_op_time = OP_TIME; g_op_time = OP_TIME;
g_op_pswd = read_op_pswd(); g_op_pswd = read_op_pswd();
g_working = false; g_working = false;//调试标志
g_debug_mode = false; g_debug_mode = false;
g_alarm_msg << QStringLiteral("无报警") /// 0 g_alarm_msg << QStringLiteral("无报警") /// 0
@ -219,14 +230,14 @@ Cigarette::Cigarette(QWidget* parent)
for (int i = 0; i < NumberOfSupportedCameras; i++) for (int i = 0; i < NumberOfSupportedCameras; i++)
{ {
g_display_label_conf[i].g_max[0] = false; g_display_label_conf[i].g_max[0] = false;//视图最大化
g_display_label_conf[i].g_max[1] = false; g_display_label_conf[i].g_max[1] = false;
OpenWithUserID[i] = 0xff; OpenWithUserID[i] = 0xff;//没用
production_number[i] = 0; production_number[i] = 0;//检测个数
lcdNumber_total_mat[i]->display(production_number[i]); lcdNumber_total_mat[i]->display(production_number[i]);//display 显示到界面
ok[i] = 0; ok[i] = 0;
ng[i] = 0; ng[i] = 0;
g_display_label_conf[i].g_last_mat[0] = cv::Mat::zeros(20, 20, CV_8UC3); g_display_label_conf[i].g_last_mat[0] = cv::Mat::zeros(20, 20, CV_8UC3);//放大后的图片
g_display_label_conf[i].g_last_mat[1] = cv::Mat::zeros(20, 20, CV_8UC3); g_display_label_conf[i].g_last_mat[1] = cv::Mat::zeros(20, 20, CV_8UC3);
#ifdef DRAW_RECT #ifdef DRAW_RECT
DrawRect_init(i); DrawRect_init(i);
@ -259,7 +270,7 @@ Cigarette::Cigarette(QWidget* parent)
read_modbus_config(g_modbus_conf); //初始化modbus地址 read_modbus_config(g_modbus_conf); //初始化modbus地址
//保存图片线程 //保存图片线程
saveThread.init(); saveThread.init();//初始化
#ifdef __ExportData #ifdef __ExportData
connect(&saveThread, &SaveThread::sendDataToExport, &exportDataThread, &ExportDataThread::GetDataFromSaveThread); connect(&saveThread, &SaveThread::sendDataToExport, &exportDataThread, &ExportDataThread::GetDataFromSaveThread);
#endif #endif
@ -273,20 +284,26 @@ Cigarette::Cigarette(QWidget* parent)
connect(rThread, &threadReceive::sendMsgToCigratte, this, &Cigarette::recMsgFromUdp); connect(rThread, &threadReceive::sendMsgToCigratte, this, &Cigarette::recMsgFromUdp);
rThread->start_work(); rThread->start_work();
#endif #endif
//初始化TCP数据传输线程
#ifdef __TCPSend #ifdef __TCPSend
std::string serverIp = g_sys_conf.TcpIP; std::string serverIp = g_sys_conf.TcpIP;
int serverPort = g_sys_conf.TcpPort; int serverPort = g_sys_conf.TcpPort;
tcpSendThread.init(TCP_Info_queue, serverIp, serverPort); tcpSendThread.init(TCP_Info_queue, serverIp, serverPort);
tcpSendThread.start_work(); tcpSendThread.start_work();
#endif
#ifdef __ExportData #endif
exportDataThread.init(); //初始化FTP数据传输线程
#ifdef __ExportData
string ftpip = g_sys_conf.FtpIP;
int ftpport = g_sys_conf.FtpPort;
string ftpusername = g_sys_conf.FtpUserName;
string ftpuserpwd = g_sys_conf.FtpUserPwd;
exportDataThread.init(ftpip,ftpport,ftpusername,ftpuserpwd);
connect(this, &Cigarette::sendMsgToExportData, &exportDataThread, &ExportDataThread::EDrecMsgFromCigarette); connect(this, &Cigarette::sendMsgToExportData, &exportDataThread, &ExportDataThread::EDrecMsgFromCigarette);
exportDataThread.start_work(); exportDataThread.start_work();
//connect(this, &Cigarette::sendMsgToExportData, &exportDataThread, &ExportDataThread::EDrecMsgFromCigarette);
#endif #endif
//初始化通讯PLC
m_PLCDevice = new PLCDevice; m_PLCDevice = new PLCDevice;
PLCDevice::init_plc(m_PLCDevice); PLCDevice::init_plc(m_PLCDevice);
if (m_PLCDevice->g_plc_ok) if (m_PLCDevice->g_plc_ok)
@ -315,21 +332,22 @@ Cigarette::Cigarette(QWidget* parent)
} }
std::cout << " Enumerate Cameras..." << std::endl; std::cout << " Enumerate Cameras..." << std::endl;
EnumerateCameras((SingleCamInfoStruct*)&SingleCamInfo, true, g_sys_conf); EnumerateCameras((SingleCamInfoStruct*)&SingleCamInfo, true, g_sys_conf);//枚举相机
// 剔除值清0 // 剔除值清0
int ret = m_PLCDevice->write_bit_2_plc(g_modbus_conf.shift, 1);//给PLC发送换班消息 int ret = m_PLCDevice->write_bit_2_plc(g_modbus_conf.shift, 1);//给PLC发送换班消息
#ifdef SYNC_CAMERA #ifdef SYNC_CAMERA
CreatWorkThread(0, 0, this); CreatWorkThread(0, 0, this);//创建相机公共工作线程
#endif #endif
//创建相机工作线程
for (int i = 0; i < NumberOfSupportedCameras; i++) for (int i = 0; i < NumberOfSupportedCameras; i++)
{ {
if (SingleCamInfo[i].Detect) { //读取模型文件
work_camera_nums++; if (SingleCamInfo[i].Detect) {//检测相机是否存在
work_camera_nums++;//相机数量
cam_status_mat[i]->setStyleSheet(tr("background-color: rgb(0, 170, 0);")); cam_status_mat[i]->setStyleSheet(tr("background-color: rgb(0, 170, 0);"));
QString model_path, model_name; QString model_path, model_name;
if (g_sys_conf.model_path.isEmpty()) { if (g_sys_conf.model_path.isEmpty()) {
@ -352,14 +370,15 @@ Cigarette::Cigarette(QWidget* parent)
exit(-1); exit(-1);
} }
#ifdef SYNC_CAMERA #ifdef SYNC_CAMERA
//调试模式线程
debug_thread[i].init(g_debug_queue[i], i); debug_thread[i].init(g_debug_queue[i], i);
connect(&debug_thread[i], SIGNAL(notify(int, int, cv::Mat)), this, SLOT(OnNotifyHub(int, int, cv::Mat))); connect(&debug_thread[i], SIGNAL(notify(int, int, cv::Mat)), this, SLOT(OnNotifyHub(int, int, cv::Mat)));
debug_thread[i].start_work(); debug_thread[i].start_work();
#else #else
CreatWorkThread(SingleCamInfo[i].CamClass, i, this); CreatWorkThread(SingleCamInfo[i].CamClass, i, this);//创建相机单独工作线程
#endif #endif
} }
else { else {//报警信息
QDateTime ts_start = QDateTime::currentDateTime(); QDateTime ts_start = QDateTime::currentDateTime();
QTime time = QTime::currentTime(); QTime time = QTime::currentTime();
QDateTime local(ts_start); QDateTime local(ts_start);
@ -428,9 +447,9 @@ Cigarette::Cigarette(QWidget* parent)
sThread.sendData("LockOk", g_sys_conf.FeedbackPort); sThread.sendData("LockOk", g_sys_conf.FeedbackPort);
#endif #endif
DisableDebugMode(); DisableDebugMode();
//读取PLC信息等
m_pTimer = new QTimer(this); m_pTimer = new QTimer(this);
connect(m_pTimer, SIGNAL(timeout()), this, SLOT(handleTimeout())); connect(m_pTimer, SIGNAL(timeout()), this, SLOT(handleTimeout()));//SIGNAL(timeout())周期性触发SLOT(handleTimeout())周期为start(1000);
m_pTimer->start(1000); m_pTimer->start(1000);
m_delay = new QTimer(this);//换班防连击 m_delay = new QTimer(this);//换班防连击
@ -440,19 +459,23 @@ Cigarette::Cigarette(QWidget* parent)
m_sendMsg_delay = new QTimer(this); m_sendMsg_delay = new QTimer(this);
connect(m_sendMsg_delay, SIGNAL(timeout()), this, SLOT(sendLatestData())); connect(m_sendMsg_delay, SIGNAL(timeout()), this, SLOT(sendLatestData()));
#endif #endif
//SIGNAL信号函数与SLOT槽函数参数必须对应
//无参信号对应无参槽函数
//检查操作员时间
m_op_delay = new QTimer(this); m_op_delay = new QTimer(this);
connect(m_op_delay, SIGNAL(timeout()), this, SLOT(op_timeout())); connect(m_op_delay, SIGNAL(timeout()), this, SLOT(op_timeout()));
//检查管理员时间
m_admin_delay = new QTimer(this); m_admin_delay = new QTimer(this);
connect(m_admin_delay, SIGNAL(timeout()), this, SLOT(admin_timeout())); connect(m_admin_delay, SIGNAL(timeout()), this, SLOT(admin_timeout()));
//定时自动清理照片
clean_pTimer = new QTimer(this); clean_pTimer = new QTimer(this);
connect(clean_pTimer, SIGNAL(timeout()), this, SLOT(CleanThreadStartAuto())); connect(clean_pTimer, SIGNAL(timeout()), this, SLOT(CleanThreadStartAuto()));
clean_pTimer->start(3600000); clean_pTimer->start(3600000);
//报警标签双击消警
connect(ui.label_alarm, SIGNAL(QlabelDoubleClick()), this, SLOT(OnCancelAlarm()));//
connect(ui.label_alarm, SIGNAL(QlabelDoubleClick()), this, SLOT(OnCancelAlarm()));//报警标签双击消警 //无参对有参需要利用信号转发器QSignalMapper(this)
//信号转发器
image_lable_DBsignalMapper0 = new QSignalMapper(this); image_lable_DBsignalMapper0 = new QSignalMapper(this);
image_lable_DBsignalMapper1 = new QSignalMapper(this); image_lable_DBsignalMapper1 = new QSignalMapper(this);
image_lable_TPsignalMapper0 = new QSignalMapper(this); image_lable_TPsignalMapper0 = new QSignalMapper(this);
@ -461,11 +484,14 @@ Cigarette::Cigarette(QWidget* parent)
pTimer_Cam_signalMapper = new QSignalMapper(this); pTimer_Cam_signalMapper = new QSignalMapper(this);
toolButton_cam_signalMapper = new QSignalMapper(this); toolButton_cam_signalMapper = new QSignalMapper(this);
RotateReleased_signalMapper = new QSignalMapper(this); RotateReleased_signalMapper = new QSignalMapper(this);
for (int i = 0; i < NumberOfSupportedCameras; i++) for (int i = 0; i < NumberOfSupportedCameras; i++)
{ {
//SIGNAL信号函数与SLOT槽函数参数必须对应
m_pTimer_Cam_mat[i] = new QTimer(this); m_pTimer_Cam_mat[i] = new QTimer(this);
connect(m_pTimer_Cam_mat[i], SIGNAL(timeout()), pTimer_Cam_signalMapper, SLOT(map())); connect(m_pTimer_Cam_mat[i], SIGNAL(timeout()), pTimer_Cam_signalMapper, SLOT(map()));
pTimer_Cam_signalMapper->setMapping(m_pTimer_Cam_mat[i], i); pTimer_Cam_signalMapper->setMapping(m_pTimer_Cam_mat[i], i);//此句执行后map()=>mapped(int);相当于无参变有参
connect(display_lable_mat[i][0], SIGNAL(QlabelDoubleClick()), image_lable_DBsignalMapper0, SLOT(map())); connect(display_lable_mat[i][0], SIGNAL(QlabelDoubleClick()), image_lable_DBsignalMapper0, SLOT(map()));
image_lable_DBsignalMapper0->setMapping(display_lable_mat[i][0], i << 4 | 0); image_lable_DBsignalMapper0->setMapping(display_lable_mat[i][0], i << 4 | 0);
@ -489,6 +515,8 @@ Cigarette::Cigarette(QWidget* parent)
RotateReleased_signalMapper->setMapping(rotate_mat[i], i); RotateReleased_signalMapper->setMapping(rotate_mat[i], i);
} }
//SIGNAL信号函数与SLOT槽函数参数必须对应
//有参对有参
connect(toolButton_cam_signalMapper, SIGNAL(mapped(int)), this, SLOT(OnToolButtonCamReleasedHub(int))); connect(toolButton_cam_signalMapper, SIGNAL(mapped(int)), this, SLOT(OnToolButtonCamReleasedHub(int)));
//connect(pTimer_Cam_signalMapper, SIGNAL(mapped(int)), this, SLOT(OpenCamTimeoutHub(int))); //connect(pTimer_Cam_signalMapper, SIGNAL(mapped(int)), this, SLOT(OpenCamTimeoutHub(int)));
connect(image_lable_DBsignalMapper0, SIGNAL(mapped(int)), this, SLOT(OnDBClickHub(int))); connect(image_lable_DBsignalMapper0, SIGNAL(mapped(int)), this, SLOT(OnDBClickHub(int)));
@ -531,7 +559,7 @@ Cigarette::Cigarette(QWidget* parent)
} }
if (m_PLCDevice->g_plc_ok) { if (m_PLCDevice->g_plc_ok) {
BeforeWork(g_sys_conf.shoot); BeforeWork(g_sys_conf.shoot);//预热
int ret = m_PLCDevice->write_bit_2_plc(g_modbus_conf.work, 1); int ret = m_PLCDevice->write_bit_2_plc(g_modbus_conf.work, 1);
ui.label_title->setStyleSheet(tr("background-color: rgb(0, 170, 0);")); ui.label_title->setStyleSheet(tr("background-color: rgb(0, 170, 0);"));
#ifdef __UDPSend #ifdef __UDPSend
@ -994,7 +1022,7 @@ void Cigarette::OnToolButtonCamReleasedHub(int Num)
QMessageBox::information(NULL, QStringLiteral("权限检查"), QStringLiteral("请先点击解锁按钮,进入管理员模式"), QMessageBox::Ok); QMessageBox::information(NULL, QStringLiteral("权限检查"), QStringLiteral("请先点击解锁按钮,进入管理员模式"), QMessageBox::Ok);
} }
} }
//重连相机
void Cigarette::ReconnectCamHub(int Num) void Cigarette::ReconnectCamHub(int Num)
{ {
//close //close
@ -1007,7 +1035,6 @@ void Cigarette::ReconnectCamHub(int Num)
} }
} }
} }
void Cigarette::OpenCamTimeoutHub(int Num) //重新打开相机 void Cigarette::OpenCamTimeoutHub(int Num) //重新打开相机
{ {
//open //open
@ -1024,14 +1051,14 @@ void Cigarette::OnKey(QKeyEvent* event)
int Cnt = CurOpLabel & 0x0f; int Cnt = CurOpLabel & 0x0f;
std::lock_guard<std::mutex> locker(g_display_label_conf[Num].lock); std::lock_guard<std::mutex> locker(g_display_label_conf[Num].lock);
if (event->key() == Qt::Key_Escape && event->isAutoRepeat() == false) if (event->key() == Qt::Key_Escape && event->isAutoRepeat() == false)//画框Esc清除参数
{ {
if (g_display_label_conf[Num].RectVet[Cnt].size()) if (g_display_label_conf[Num].RectVet[Cnt].size())
{ {
g_display_label_conf[Num].RectVet[Cnt].pop_back(); g_display_label_conf[Num].RectVet[Cnt].pop_back();
} }
} }
else if (event->key() == Qt::Key_Return && event->isAutoRepeat() == false) else if (event->key() == Qt::Key_Return && event->isAutoRepeat() == false)//画框回车保存参数
{ {
std::fstream cfg_file; std::fstream cfg_file;
char buf[256]; char buf[256];
@ -1537,7 +1564,7 @@ void Cigarette::admin_timeout()
} }
} }
void Cigarette::handleTimeout() void Cigarette::handleTimeout()//获取时间读取PLC产量、剔除数检测相机状态读取PLC报警信息
{ {
QDateTime ts_start = QDateTime::currentDateTime(); QDateTime ts_start = QDateTime::currentDateTime();
QTime time = QTime::currentTime(); QTime time = QTime::currentTime();
@ -2044,8 +2071,8 @@ void Cigarette::on_pushButton_clear_released()//换班
g_op_time = OP_TIME; g_op_time = OP_TIME;
ui.pushButton_clear->setEnabled(false); ui.pushButton_clear->setEnabled(false);
m_delay->setSingleShot(true); m_delay->setSingleShot(true);//执行一次
m_delay->start(5000); m_delay->start(5000);//5秒
Sleep(500); Sleep(500);
for (int i = 0; i < NumberOfSupportedCameras; i++) for (int i = 0; i < NumberOfSupportedCameras; i++)
{ {
@ -2150,15 +2177,15 @@ QString Cigarette::read_op_pswd()
bool Cigarette::read_conf(ConfPath& conf_path) { bool Cigarette::read_conf(ConfPath& conf_path) {
std::fstream conf_file; std::fstream conf_file;
conf_file.open(CONFPATH); conf_file.open(CONFPATH);
if (!conf_file.is_open()) { if (!conf_file.is_open()) {//判断能否打开文件
std::cout << "Error: Open conf path file " << CONFPATH << std::endl; std::cout << "Error: Open conf path file " << CONFPATH << std::endl;
return false; return false;
} }
while (!conf_file.eof()) { while (!conf_file.eof()) {//从头读到尾完成后conf_file.eof()==TRUE
char tmp[256] = ""; char tmp[256] = "";
conf_file.getline(tmp, 256); conf_file.getline(tmp, 256);
std::string line(tmp); std::string line(tmp);
if (line.length() > 0) { if (line.length() > 0) {//按行读取
size_t pos = line.find('='); size_t pos = line.find('=');
std::string tmp_key = line.substr(0, pos); std::string tmp_key = line.substr(0, pos);
if (tmp_key == "CONF_PATH") { if (tmp_key == "CONF_PATH") {
@ -2566,6 +2593,22 @@ bool Cigarette::read_sys_config(SysConf& conf, QString conf_path)
{ {
conf.TcpPort = atoi(line.substr(pos + 1).c_str()); conf.TcpPort = atoi(line.substr(pos + 1).c_str());
} }
else if (tmp_key == "FtpIP")
{
conf.FtpIP = line.substr(pos + 1);
}
else if (tmp_key == "FtpPort")
{
conf.FtpPort = atoi(line.substr(pos + 1).c_str());
}
else if (tmp_key == "FtpUserName")
{
conf.FtpUserName= line.substr(pos + 1);
}
else if (tmp_key == "FtpUserPwd")
{
conf.FtpUserPwd = line.substr(pos + 1);
}
} }
} }
@ -3127,11 +3170,11 @@ bool Cigarette::ControlCamOpenOrClose(int Num, bool OpenOrClose)
else if (SingleCamInfo[Num].CamClass == HIKClassID) else if (SingleCamInfo[Num].CamClass == HIKClassID)
{ {
qDebug() << "open for hik"; qDebug() << "open for hik";
int nRet = MV_OK; int nRet = MV_OK;//海康内部定义MV_OK = 0x0000000;
void* camhandle; void* camhandle;
nRet = MV_CC_CreateHandle(&camhandle, HIKCamera::stDeviceList.pDeviceInfo[SingleCamInfo[Num].unfiltered_num]); nRet = MV_CC_CreateHandle(&camhandle, HIKCamera::stDeviceList.pDeviceInfo[SingleCamInfo[Num].unfiltered_num]);
HIKCamHandle[Num] = camhandle; HIKCamHandle[Num] = camhandle;
nRet = MV_CC_OpenDevice(camhandle); nRet = MV_CC_OpenDevice(camhandle);//打开相机成功返回MV_OK
if (nRet) if (nRet)
{ {
MV_CC_CloseDevice(camhandle); MV_CC_CloseDevice(camhandle);
@ -3143,6 +3186,7 @@ bool Cigarette::ControlCamOpenOrClose(int Num, bool OpenOrClose)
} }
if (HIKCamera::stDeviceList.pDeviceInfo[SingleCamInfo[Num].unfiltered_num]->nTLayerType == MV_GIGE_DEVICE) if (HIKCamera::stDeviceList.pDeviceInfo[SingleCamInfo[Num].unfiltered_num]->nTLayerType == MV_GIGE_DEVICE)
{ {
//配置网口相机
int nPacketSize = MV_CC_GetOptimalPacketSize(camhandle); int nPacketSize = MV_CC_GetOptimalPacketSize(camhandle);
if (nPacketSize > 0) if (nPacketSize > 0)
{ {
@ -3236,7 +3280,7 @@ bool Cigarette::ControlCamOpenOrClose(int Num, bool OpenOrClose)
if (!g_debug_mode) if (!g_debug_mode)
connect(pHIKCaptureThread[Num], SIGNAL(updateStatistics(const QString&, int)), this, SLOT(updateStatisticsHub(const QString&, int))); connect(pHIKCaptureThread[Num], SIGNAL(updateStatistics(const QString&, int)), this, SLOT(updateStatisticsHub(const QString&, int)));
pThread[Num]->start(); pThread[Num]->start();
if (pThread[Num]->isRunning()) if (pThread[Num]->isRunning())//线程开始工作后打印消息
{ {
qDebug() << "hik pThread OK"; qDebug() << "hik pThread OK";
SingleCamInfo[Num].IsOpen = true; SingleCamInfo[Num].IsOpen = true;
@ -3250,6 +3294,7 @@ bool Cigarette::ControlCamOpenOrClose(int Num, bool OpenOrClose)
if (SingleCamInfo[Num].CamClass == BalluffClassID) if (SingleCamInfo[Num].CamClass == BalluffClassID)
{ {
qDebug() << "close for balluff"; qDebug() << "close for balluff";
//取消函数连接
disconnect(pThread[Num], SIGNAL(started()), pCaptureThread[Num], SLOT(process())); disconnect(pThread[Num], SIGNAL(started()), pCaptureThread[Num], SLOT(process()));
//disconnect(pCaptureThread[Num], SIGNAL(error(QString)), this, SLOT(errorString(QString))); //disconnect(pCaptureThread[Num], SIGNAL(error(QString)), this, SLOT(errorString(QString)));
disconnect(pCaptureThread[Num], SIGNAL(finished()), pThread[Num], SLOT(quit())); disconnect(pCaptureThread[Num], SIGNAL(finished()), pThread[Num], SLOT(quit()));
@ -3542,7 +3587,7 @@ void Cigarette::EnableDebugMode()
} }
g_debug_mode = true; g_debug_mode = true;
} }
//非调试模式
void Cigarette::DisableDebugMode() void Cigarette::DisableDebugMode()
{ {
for (int i = 0; i < NumberOfSupportedCameras; i++) for (int i = 0; i < NumberOfSupportedCameras; i++)
@ -3600,7 +3645,7 @@ void Cigarette::CleanThreadStart()
QThread* handleThread = new QThread(); QThread* handleThread = new QThread();
CleanWorkThread* cleanWorkThread = new CleanWorkThread(); CleanWorkThread* cleanWorkThread = new CleanWorkThread();
cleanWorkThread->moveToThread(handleThread); cleanWorkThread->moveToThread(handleThread);//依附到handleThread线程
connect(handleThread, &QThread::started, cleanWorkThread, &CleanWorkThread::startWork); connect(handleThread, &QThread::started, cleanWorkThread, &CleanWorkThread::startWork);
connect(cleanWorkThread, &CleanWorkThread::workStart, cleanWorkThread, &CleanWorkThread::setSel); connect(cleanWorkThread, &CleanWorkThread::workStart, cleanWorkThread, &CleanWorkThread::setSel);

@ -215,18 +215,20 @@ private:
threadSend sThread; threadSend sThread;
threadReceive* rThread; threadReceive* rThread;
#endif #endif
//TCP数据传输
#ifdef __TCPSend #ifdef __TCPSend
private: private:
threadSendTCP tcpSendThread; threadSendTCP tcpSendThread;
#endif #endif
public slots: public slots://槽函数:接收信号
void CleanThreadStartAuto(); void CleanThreadStartAuto();
#ifdef __UDPSend #ifdef __UDPSend
void recMsgFromUdp(QString data); void recMsgFromUdp(QString data);
#endif #endif
//void ClogThreadStart(); //void ClogThreadStart();
signals: signals://信号函数:发信号
void sengMsgToClog(QString); void sengMsgToClog(QString);
void sendMsgToExportData(); void sendMsgToExportData();
}; };

@ -6,7 +6,8 @@
#include <ShlObj.h> #include <ShlObj.h>
#include <Commdlg.h> #include <Commdlg.h>
#include <tchar.h> #include <tchar.h>
//字符分割
//str传进来的字符串pattern分隔符out分割后的结果。例子Cigarette::read_plc_items()
int string_split(std::string str, std::string pattern, std::vector<std::string>& out) int string_split(std::string str, std::string pattern, std::vector<std::string>& out)
{ {
std::string::size_type pos; std::string::size_type pos;
@ -31,19 +32,19 @@ int string_split(std::string str, std::string pattern, std::vector<std::string>&
std::string format(const char* pszFmt, ...) std::string format(const char* pszFmt, ...)
{ {
std::string str; std::string str;
va_list args; va_list args;//表示一个变长参数列表
va_start(args, pszFmt); va_start(args, pszFmt);//用于在使用可变参数函数时获取可变参数的起始地址
{ {
int nLength = _vscprintf(pszFmt, args); int nLength = _vscprintf(pszFmt, args);//格式化字符串,获取字符串长度
nLength += 1; nLength += 1;
std::vector<char> chars(nLength); std::vector<char> chars(nLength);
_vsnprintf(chars.data(), nLength, pszFmt, args); _vsnprintf(chars.data(), nLength, pszFmt, args);//指定字符串大小
str.assign(chars.data()); str.assign(chars.data());//赋值
} }
va_end(args); va_end(args);//清除va_list数据
return str; return str;
} }
//画框:胶点范围检测
void DrawSelectRects(cv::Mat input, DisplayLabelConf& t_DisplayLabelConf, int Cnt) void DrawSelectRects(cv::Mat input, DisplayLabelConf& t_DisplayLabelConf, int Cnt)
{ {
if (t_DisplayLabelConf.Flag[Cnt] & DisplayLabel_Type_Bit) { if (t_DisplayLabelConf.Flag[Cnt] & DisplayLabel_Type_Bit) {
@ -75,11 +76,11 @@ void DrawSelectRects(cv::Mat input, DisplayLabelConf& t_DisplayLabelConf, int Cn
} }
bool CheckSelectRects( bool CheckSelectRects(
cv::Mat input, cv::Mat input,//图像
std::vector<std::vector<std::pair<int, cv::Rect> > >& VecRects, std::vector<std::vector<std::pair<int, cv::Rect> > >& VecRects,//胶点结果
int VecCnt, int VecCnt,//第几张图像
DisplayLabelConf& t_DisplayLabelConf, DisplayLabelConf& t_DisplayLabelConf,//画的框
int LabelCnt int LabelCnt//第几个框
) )
{ {
bool find; bool find;
@ -120,7 +121,7 @@ bool CheckSelectRects(
} }
return false; return false;
} }
//获取路径下的所有文件放到files里。例子void Cigarette::TestImgs()
void getFiles(std::string path, std::vector<std::string>& files) void getFiles(std::string path, std::vector<std::string>& files)
{ {
//文件句柄 //文件句柄
@ -140,7 +141,7 @@ void getFiles(std::string path, std::vector<std::string>& files)
_findclose(hFile); _findclose(hFile);
} }
} }
//wstring是宽字符(中文汉字)占2个字节string是窄字符(英文啥的)占1个字节
std::string WstringToString(std::wstring wstr) std::string WstringToString(std::wstring wstr)
{ {
int nLen = wcslen(wstr.c_str()); int nLen = wcslen(wstr.c_str());
@ -168,7 +169,7 @@ char* LPWSTR2LPSTR(LPWSTR lpwszStrIn)
return pszOut; return pszOut;
} }
//从string s的位置pos开始向后找找到第一个等于x的位置返回其位置 //从string s的位置start开始向后找找到第一个等于x的位置返回其位置
//找到,返回找到的位置,找不到返回-1 //找到,返回找到的位置,找不到返回-1
int __find(const std::string s, const int start, const char x) { int __find(const std::string s, const int start, const char x) {
if (start >= s.length())return -1; if (start >= s.length())return -1;

@ -7,7 +7,7 @@
//#define __DEBUG //debug信息输出功能 //#define __DEBUG //debug信息输出功能
//#define __UDPSend //网络发送功能 //#define __UDPSend //网络发送功能
#define __TCPSend // TCP发送 //#define __TCPSend // TCP发送
#define USB_BASLER_NEW_FW //使用basler定制固件 #define USB_BASLER_NEW_FW //使用basler定制固件
//#define IMM_PROCESS //拍照后立马处理,不等校验信号 //#define IMM_PROCESS //拍照后立马处理,不等校验信号
//#define IMM_FEED_BACK //处理完后立马反馈,不等校验信号 //#define IMM_FEED_BACK //处理完后立马反馈,不等校验信号
@ -19,9 +19,9 @@
//#define CAP_FEED_BACK //拍照时也检测有没有测试结果,有的话就反馈 //#define CAP_FEED_BACK //拍照时也检测有没有测试结果,有的话就反馈
//#define DOUBLE_FEED_BACK //一次ng两次反馈ng信号 //#define DOUBLE_FEED_BACK //一次ng两次反馈ng信号
#endif #endif
//#define identify_Hik_YSXID//识别海康相机YSXID #define identify_Hik_YSXID//识别海康相机YSXID
//#define __ExportData // 输出检测数据到XML文档 //#define __ExportData // 输出检测数据到XML文档
#define DRAW_RECT // 鼠标画框功能 //#define DRAW_RECT // 鼠标画框功能
#define SYNC_CAMERA //相机同步处理图片 #define SYNC_CAMERA //相机同步处理图片
#define Queue_Size 15 #define Queue_Size 15
@ -35,7 +35,7 @@
#endif #endif
// 主界面基本参数配置文件 // 主界面基本参数配置文件
#define CONFPATH "D:/conf/conf_path.txt" #define CONFPATH "D:/Release/conf_path.txt"
//#define CONFIGURE_FILE "D:/conf/conf.txt" //#define CONFIGURE_FILE "D:/conf/conf.txt"
// 相机旋转角度配置文件 // 相机旋转角度配置文件
#define ROTATE_FILE "rotate.txt" #define ROTATE_FILE "rotate.txt"
@ -110,8 +110,12 @@ public:
//MonitorPort+NumberOfSupportedCameras为图像端口 //MonitorPort+NumberOfSupportedCameras为图像端口
//MonitorPort+NumberOfSupportedCameras*2为发送命令端口,也就是FeedbackPort //MonitorPort+NumberOfSupportedCameras*2为发送命令端口,也就是FeedbackPort
//MonitorPort+NumberOfSupportedCameras*2+1为接受命令端口 //MonitorPort+NumberOfSupportedCameras*2+1为接受命令端口
std::string TcpIP; // TCP服务器端ip地址 std::string TcpIP; // TCP服务器端ip地址
int TcpPort; // TCP服务器端端口号 int TcpPort; // TCP服务器端端口号
std::string FtpIP; // FTP服务器端ip地址
int FtpPort; // FTP服务器端端口号
std::string FtpUserName; // FTP服务器登录账号
std::string FtpUserPwd; // FTP服务器登录密码
SysConf() SysConf()
{ {
@ -148,6 +152,11 @@ public:
FeedbackPort = MonitorPort + NumberOfSupportedCameras * 2; FeedbackPort = MonitorPort + NumberOfSupportedCameras * 2;
TcpIP = "192.168.1.126"; TcpIP = "192.168.1.126";
TcpPort = 8888; TcpPort = 8888;
FtpIP = "192.168.1.126";
FtpPort = 111;
FtpUserName = "111";
FtpUserPwd = "111";
} }
}; };

@ -756,18 +756,28 @@ void DialogSetup::write_config()
memset(buf, 0, 256); memset(buf, 0, 256);
sprintf(buf, "MonitorIP=%s\n", g_sys_conf.MonitorIP.c_str()); sprintf(buf, "MonitorIP=%s\n", g_sys_conf.MonitorIP.c_str());
cfg_file.write(buf, strlen(buf)); cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256); memset(buf, 0, 256);
cfg_file.write(buf, strlen(buf)); cfg_file.write(buf, strlen(buf));
sprintf(buf, "MonitorPort=%d\n", g_sys_conf.MonitorPort); sprintf(buf, "MonitorPort=%d\n", g_sys_conf.MonitorPort);
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256); memset(buf, 0, 256);
sprintf(buf, "TcpIP=%s\n", g_sys_conf.TcpIP.c_str()); sprintf(buf, "TcpIP=%s\n", g_sys_conf.TcpIP.c_str());
cfg_file.write(buf, strlen(buf)); cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256); memset(buf, 0, 256);
cfg_file.write(buf, strlen(buf)); cfg_file.write(buf, strlen(buf));
sprintf(buf, "TcpPort=%d\n", g_sys_conf.TcpPort); sprintf(buf, "TcpPort=%d\n", g_sys_conf.TcpPort);
memset(buf, 0, 256);
sprintf(buf, "FtpIP=%s\n", g_sys_conf.FtpIP.c_str());
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
cfg_file.write(buf, strlen(buf));
sprintf(buf, "FtpPort=%d\n", g_sys_conf.FtpPort);
memset(buf, 0, 256);
sprintf(buf, "FtpUserName=%s\n", g_sys_conf.FtpUserName.c_str());
cfg_file.write(buf, strlen(buf));
memset(buf, 0, 256);
sprintf(buf, "FtpUserPwd=%s\n", g_sys_conf.FtpUserPwd.c_str());
cfg_file.write(buf, strlen(buf)); cfg_file.write(buf, strlen(buf));
} }
cfg_file.close(); cfg_file.close();

@ -13,9 +13,11 @@ Cigarette* cg;
extern SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue; extern SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue;
extern ConfPath g_conf_path; extern ConfPath g_conf_path;
extern bool flag; extern bool flag;
extern SysConf g_sys_conf; //系统配置参数
ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent) ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent)
{ {
//第一步执行
cg->read_conf(g_conf_path); cg->read_conf(g_conf_path);
for (int index = 0; index < NumberOfSupportedCameras; index++) for (int index = 0; index < NumberOfSupportedCameras; index++)
{ {
@ -30,19 +32,29 @@ ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent)
pDocument[index]->InsertFirstChild(declaration); pDocument[index]->InsertFirstChild(declaration);
} }
} }
init(ip,port,username,userpwd);
cout << "11111111111111";
hint = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0); hint = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
if (hint == NULL) { if (hint == NULL) {
return; return;
} }
if (!ConnectFtp()) if (!ConnectFtp(&ip, &port, &username, &userpwd))
qDebug() << "First connect FTP failed because " << GetLastError(); qDebug() << "First connect FTP failed because " << GetLastError();
} }
void ExportDataThread::init() void ExportDataThread::init(string ip_, int port_, string username_, string userpwd_)
{ {
//第三部执行
ip = ip_;
port = port_;
username = username_;
userpwd = userpwd_;
cout << "333333ftp ip =" << ip << "| prot =" << port << endl;
cout << "333333username =" << username << "| pwd =" << userpwd << endl;
b_quit = false; b_quit = false;
flag = false; flag = false;
} }
void ExportDataThread::start_work() void ExportDataThread::start_work()
@ -59,22 +71,26 @@ void ExportDataThread::stop()
InternetCloseHandle(hint); InternetCloseHandle(hint);
} }
bool ExportDataThread::ConnectFtp() { bool ExportDataThread::ConnectFtp(string *ip_, int *port_, string *username_, string *userpwd_) {
// FTP地址
string ftpServer = "192.168.1.170"; //// FTP地址
/* 端口号一般为21 */ //string ftpServer = "192.168.1.180";
int port = 666; ///* 端口号一般为21 */
/* 用户名 */ //int port = 666;
string userName = "FTP2"; ///* 用户名 */
/* 密码 */ //string userName = "FTP2";
string pwd = "123"; ///* 密码 */
//string pwd = "123";
int ftpport =*port_;
cout << "222ftp ip =" << ip << "| prot =" << port << endl;
cout << "222username =" << username << "| pwd =" << userpwd << endl;
if (hftp != NULL) { if (hftp != NULL) {
InternetCloseHandle(hftp); InternetCloseHandle(hftp);
hftp = NULL; hftp = NULL;
} }
// 创建ftp连接 // 创建ftp连接
hftp = InternetConnectA(hint, ftpServer.c_str(), port, userName.c_str(), pwd.c_str(), INTERNET_SERVICE_FTP, 0, 0); // hftp = InternetConnectA(hint, ftpServer.c_str(), port, userName.c_str(), pwd.c_str(), INTERNET_SERVICE_FTP, 0, 0);
hftp = InternetConnectA(hint, ip_->c_str(), ftpport, username_->c_str(), userpwd_->c_str(), INTERNET_SERVICE_FTP, 0, 0);
if (hftp == NULL) { if (hftp == NULL) {
qDebug() << "ftp connect failed because " << GetLastError(); qDebug() << "ftp connect failed because " << GetLastError();
return false; return false;
@ -82,56 +98,58 @@ bool ExportDataThread::ConnectFtp() {
else else
qDebug() << "ftp reconnect success"; qDebug() << "ftp reconnect success";
return true; return true;
}
bool _ExportDataInfo::getAverageData(map<string, float>& averageData, int index)
{
tinyxml2::XMLDocument doc;
//char xmlPath[256];
XMLError error;
map<string, float> data;
//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 = doc.LoadFile(filePath.toLocal8Bit().constData());
if (error != XML_SUCCESS)
if (doc.LoadFile(filePath.toLocal8Bit().constData()) != 0)
{
cout << "load xml file failed" << endl;
return false;
}
XMLElement* root = doc.RootElement();
XMLElement* userNode = root->FirstChildElement("Camera");
data["CameraId"] = index;
data["IsNG"] = 0;
data["IsJdExist"] = 0;
data["Total"] = 0;
while (userNode != NULL)
{
if (atoi(userNode->Attribute("Id")) == index) {
data["IsNG"]++;
data["IsJdExist"]++;
data["Total"]++;
XMLElement* IsNgNode = userNode->FirstChildElement("IsNG");
data["IsNg"] = strcmp(IsNgNode->GetText(), "TRUE");
XMLElement* IsJdExistNode = userNode->FirstChildElement("IsJdExist");
if (strcmp(IsJdExistNode->GetText(), "TRUE") == 0)
data["IsJdExist"]++;
XMLElement* TimeCostNode = userNode->FirstChildElement("TimeCost");
data["TimeCost"] += stof(TimeCostNode->GetText());
}
userNode = userNode->NextSiblingElement();//下一个兄弟节点
}
if (data["Total"] == 0)
return false;
data["TimeCost"] = data["TimeCost"] / data["Total"];
averageData = data;
return true;
} }
//bool _ExportDataInfo::getAverageData(map<string, float>& averageData, int index)
//{
// tinyxml2::XMLDocument doc;
// //char xmlPath[256];
// XMLError error;
// map<string, float> data;
// //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 = doc.LoadFile(filePath.toLocal8Bit().constData());
// if (error != XML_SUCCESS)
// if (doc.LoadFile(filePath.toLocal8Bit().constData()) != 0)
// {
// cout << "load xml file failed" << endl;
// return false;
// }
// XMLElement* root = doc.RootElement();
// XMLElement* userNode = root->FirstChildElement("Camera");
// data["CameraId"] = index;
// data["IsNG"] = 0;
// data["IsJdExist"] = 0;
// data["Total"] = 0;
// while (userNode != NULL)
// {
// if (atoi(userNode->Attribute("Id")) == index) {
// data["IsNG"]++;
// data["IsJdExist"]++;
// data["Total"]++;
// XMLElement* IsNgNode = userNode->FirstChildElement("IsNG");
// data["IsNg"] = strcmp(IsNgNode->GetText(), "TRUE");
// XMLElement* IsJdExistNode = userNode->FirstChildElement("IsJdExist");
// if (strcmp(IsJdExistNode->GetText(), "TRUE") == 0)
// data["IsJdExist"]++;
// XMLElement* TimeCostNode = userNode->FirstChildElement("TimeCost");
// data["TimeCost"] += stof(TimeCostNode->GetText());
// }
// userNode = userNode->NextSiblingElement();//下一个兄弟节点
// }
// if (data["Total"] == 0)
// return false;
// data["TimeCost"] = data["TimeCost"] / data["Total"];
//
// averageData = data;
//
// return true;
//}
//XML文件
//写数据到XML文件
int ExportDataThread::insertXMLNode(const char* xmlPath, _XMLExportDataInfo& data) int ExportDataThread::insertXMLNode(const char* xmlPath, _XMLExportDataInfo& data)
{ {
XMLElement* root = pDocument[data.cameraId]->RootElement(); XMLElement* root = pDocument[data.cameraId]->RootElement();
@ -233,6 +251,7 @@ int ExportDataThread::insertXMLNode(const char* xmlPath, _XMLExportDataInfo& dat
void ExportDataThread::run() void ExportDataThread::run()
{ {
while (!b_quit) { while (!b_quit) {
_XMLExportDataInfo element; _XMLExportDataInfo element;
export_XMLData_Info_queue->take(element); export_XMLData_Info_queue->take(element);
@ -278,7 +297,7 @@ void ExportDataThread::check_save_dir(std::string dir_path)
void ExportDataThread::EDrecMsgFromCigarette() { void ExportDataThread::EDrecMsgFromCigarette() {
flag = true; flag = true;
} }
//发送数据给服务器
void ExportDataThread::ConnectServer(QString srcPath, QString destPath) { void ExportDataThread::ConnectServer(QString srcPath, QString destPath) {
string filePath = srcPath.toLocal8Bit().constData(); string filePath = srcPath.toLocal8Bit().constData();
string remotePath = destPath.toLocal8Bit().constData(); string remotePath = destPath.toLocal8Bit().constData();
@ -308,7 +327,7 @@ void ExportDataThread::ConnectServer(QString srcPath, QString destPath) {
else { else {
while (!FtpPutFileA(hftp, filePath.c_str(), remotePath.c_str(), FTP_TRANSFER_TYPE_BINARY, 0)) { while (!FtpPutFileA(hftp, filePath.c_str(), remotePath.c_str(), FTP_TRANSFER_TYPE_BINARY, 0)) {
qDebug() << "ftp put file " << filePath.c_str() << "failed because" << GetLastError(); qDebug() << "ftp put file " << filePath.c_str() << "failed because" << GetLastError();
if (!ConnectFtp()) if (!ConnectFtp(&ip, &port, &username, &userpwd))
qDebug() << "connect FTP failed because " << GetLastError(); qDebug() << "connect FTP failed because " << GetLastError();
} }
} }
@ -321,6 +340,7 @@ void ExportDataThread::ConnectServer(QString srcPath, QString destPath) {
int pos = tempFilePath.find_last_of('/'); int pos = tempFilePath.find_last_of('/');
string destFileName = tempFilePath.substr(pos + 1); string destFileName = tempFilePath.substr(pos + 1);
check_save_dir(remotePath + tempFilePath.substr(0, pos + 1)); check_save_dir(remotePath + tempFilePath.substr(0, pos + 1));
//发送函数
if (!FtpPutFileA(hftp, files[i].c_str(), destFileName.c_str(), FTP_TRANSFER_TYPE_BINARY, 0)) if (!FtpPutFileA(hftp, files[i].c_str(), destFileName.c_str(), FTP_TRANSFER_TYPE_BINARY, 0))
qDebug() << "ftp put files failed because " << GetLastError(); qDebug() << "ftp put files failed because " << GetLastError();
} }

@ -105,6 +105,8 @@ signals:
public: public:
string ip, username, userpwd;
int port;
ExportDataThread(QObject* parent = 0); ExportDataThread(QObject* parent = 0);
~ExportDataThread() ~ExportDataThread()
{ {
@ -114,12 +116,12 @@ public:
wait(); wait();
} }
void init(); void init(string ip_, int port_, string username_, string userpwd_);
void start_work(); void start_work();
void stop(); void stop();
//int insertXMLNode(const char* xmlPath, _ExportDataInfo& data); //int insertXMLNode(const char* xmlPath, _ExportDataInfo& data);
int insertXMLNode(const char* xmlPath, _XMLExportDataInfo& data); int insertXMLNode(const char* xmlPath, _XMLExportDataInfo& data);
bool ConnectFtp(); bool ConnectFtp(string *ip_, int *port_, string *username_, string *userpwd_);
void ConnectServer(QString srcPath, QString destPath); void ConnectServer(QString srcPath, QString destPath);
void GetFiles(string path, std::vector<string>& files); void GetFiles(string path, std::vector<string>& files);
@ -134,6 +136,7 @@ public:
HINTERNET hint = NULL; HINTERNET hint = NULL;
HINTERNET hftp = NULL; HINTERNET hftp = NULL;
public slots: public slots:
void EDrecMsgFromCigarette(); void EDrecMsgFromCigarette();
void GetDataFromSaveThread(QString filePath); void GetDataFromSaveThread(QString filePath);

@ -13,12 +13,12 @@
#include <opencv2/imgproc/types_c.h> #include <opencv2/imgproc/types_c.h>
extern SyncQueue<std::pair<std::string, cv::Mat>>* g_save_queue; //图像保存队列 extern SyncQueue<std::pair<std::string, cv::Mat>>* g_save_queue; //图像保存队列
extern bool IsALL;
class SaveThread : public QThread class SaveThread : public QThread
{ {
Q_OBJECT Q_OBJECT
signals: signals:
void sendDataToExport(QString filePath); void sendDataToExport(QString filePath);//XML发送信号函数
public: public:
SaveThread(QObject* parent = 0) : QThread(parent) SaveThread(QObject* parent = 0) : QThread(parent)
@ -60,8 +60,8 @@ protected:
std::size_t found = file_name.find_last_of("/\\"); std::size_t found = file_name.find_last_of("/\\");
std::string dir_path = file_name.substr(0, found); std::string dir_path = file_name.substr(0, found);
check_save_dir(dir_path); check_save_dir(dir_path);
bool b_save = cv::imwrite(file_name, image); bool b_save = cv::imwrite(file_name, image);//存本地
if (b_save) if (IsALL && b_save)
{ {
//sendDataToExport(QString::fromStdString(file_name)); //sendDataToExport(QString::fromStdString(file_name));
sendDataToExport(QString::fromLocal8Bit(QByteArray::fromRawData(file_name.c_str(), file_name.size()))); sendDataToExport(QString::fromLocal8Bit(QByteArray::fromRawData(file_name.c_str(), file_name.size())));

@ -25,6 +25,7 @@ extern SyncQueue<_UDPSendInfo>* UDP_Info_queue;
#endif #endif
#ifdef __TCPSend #ifdef __TCPSend
extern SyncQueue<_TCPSendInfo>* TCP_Info_queue; extern SyncQueue<_TCPSendInfo>* TCP_Info_queue;
extern threadSendTCP tcpSendThread;
#endif #endif
#ifdef __ExportData #ifdef __ExportData
extern ExportDataThread exportDataThread; extern ExportDataThread exportDataThread;
@ -32,6 +33,7 @@ extern ExportDataThread exportDataThread;
extern PLCDevice* m_PLCDevice; extern PLCDevice* m_PLCDevice;
extern bool g_debug_mode; extern bool g_debug_mode;
bool IsALL = false;//是否是全存
SyncWorkThread::~SyncWorkThread() SyncWorkThread::~SyncWorkThread()
{ {
stop(); stop();
@ -176,7 +178,7 @@ void SyncWorkThread::run()
bool IsNG = false; bool IsNG = false;
int ngReason = 0; int ngReason = 0;
QMap<int, QString> ng_reason_maps; QMap<int, QString> ng_reason_maps;
ng_reason_maps[0] = "unknow"; ng_reason_maps[0] = "OK";
ng_reason_maps[1] = "less_than_setting"; ng_reason_maps[1] = "less_than_setting";
ng_reason_maps[2] = "too_diff_from_model"; ng_reason_maps[2] = "too_diff_from_model";
ng_reason_maps[3] = "out_of_setting_range"; ng_reason_maps[3] = "out_of_setting_range";
@ -192,27 +194,28 @@ void SyncWorkThread::run()
IsNG = false; IsNG = false;
ngReason = 0; ngReason = 0;
} }
if (local_SysConf.save == 2)//三张照片分别存储 // if (local_SysConf.save == 2)//三张照片分别存储
{ // {
/// 合成work_camera_nums * unit_count 宫格图像 // IsALL = true;
cv::Mat m = vec_in[index].clone(); // /// 合成work_camera_nums * unit_count 宫格图像
QString file_name; // cv::Mat m = vec_in[index].clone();
merge_index = j * unit_count + index + 1; // QString file_name;
roi = cv::Rect(index * m.cols, j * m.rows, m.cols, m.rows); // merge_index = j * unit_count + index + 1;
m.copyTo(merge_image(roi)); // roi = cv::Rect(index * m.cols, j * m.rows, m.cols, m.rows);
// m.copyTo(merge_image(roi));
if (merge_index == work_camera_nums * unit_count) { //
file_name = g_conf_path.save_pics_path + "/" // if (merge_index == work_camera_nums * unit_count) {
+ now_ts.toString("yyyy-MM-dd") + "/" // file_name = g_conf_path.save_pics_path + "/"
+ now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + ".jpg"; // + now_ts.toString("yyyy-MM-dd") + "/"
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), merge_image)); // + now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") +"_" +ng_reason_maps[ngReason] + ".jpg";
#ifdef __TCPSend // g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), merge_image));
QString sendName = now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + ".jpg"; //#ifdef __TCPSend
TCPSendInfo.pics_name = sendName.toLocal8Bit().constData(); // QString sendName = now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + ".jpg";
TCP_Info_queue->put(TCPSendInfo); // TCPSendInfo.pics_name = sendName.toLocal8Bit().constData();
#endif // TCP_Info_queue->put(TCPSendInfo);
} //#endif
} // }
// }
} }
if (unit_count >= 2) { if (unit_count >= 2) {
image1 = vec_out[(result_index[i]) % 2].clone(); image1 = vec_out[(result_index[i]) % 2].clone();
@ -247,7 +250,6 @@ void SyncWorkThread::run()
#endif #endif
} }
result_index[i]++; result_index[i]++;
if (!IsNG) if (!IsNG)
{ {
if (!g_debug_mode) if (!g_debug_mode)
@ -260,6 +262,7 @@ void SyncWorkThread::run()
} }
else else
{ {
IsALL = false;
if (!g_debug_mode) if (!g_debug_mode)
{ {
#ifdef SYNC_CAMERA #ifdef SYNC_CAMERA
@ -271,6 +274,7 @@ void SyncWorkThread::run()
if ((local_SysConf.save == 2) || (local_SysConf.save == 1)) if ((local_SysConf.save == 2) || (local_SysConf.save == 1))
{ {
for (int index = 0; index < unit_count; index++) for (int index = 0; index < unit_count; index++)
{ {
cv::Mat m = vec_in[index].clone(); cv::Mat m = vec_in[index].clone();
@ -280,10 +284,7 @@ void SyncWorkThread::run()
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) + now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] + "#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg"; ".jpg";
QString remotePath = "/image/ng/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m)); g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
m = vec_out[index].clone(); m = vec_out[index].clone();
@ -293,15 +294,13 @@ void SyncWorkThread::run()
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) + now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] + "#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg"; ".jpg";
remotePath = "/image/ng_result/" +
now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + QString::number(local_camera_number + 1) +
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
//g_save_queue->put(std::make_pair(file_name.toStdString(), m));
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m)); g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
} }
} }
} }
#ifdef SYNC_CAMERA #ifdef SYNC_CAMERA
if (!g_debug_mode) if (!g_debug_mode)
{ {
@ -312,6 +311,31 @@ void SyncWorkThread::run()
emit notify(local_camera_number, 1, image2); emit notify(local_camera_number, 1, image2);
} }
#endif #endif
for (int index = 0; index < unit_count; index++)
{
if (local_SysConf.save == 2)//照片存储
{
IsALL = true;
/// 合成work_camera_nums * unit_count 宫格图像
cv::Mat m = vec_in[index].clone();
QString file_name;
merge_index = j * unit_count + index + 1;
roi = cv::Rect(index * m.cols, j * m.rows, m.cols, m.rows);
m.copyTo(merge_image(roi));
if (merge_index == work_camera_nums * unit_count) {
file_name = g_conf_path.save_pics_path + "/"
+ now_ts.toString("yyyy-MM-dd") + "/"
+ now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + "_" + ng_reason_maps[ngReason] + ".jpg";
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), merge_image));
#ifdef __TCPSend
QString sendName = now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + ng_reason_maps[ngReason] + ".jpg";
TCPSendInfo.pics_name = sendName.toLocal8Bit().constData();
TCP_Info_queue->put(TCPSendInfo);
#endif
}
}
}
} }
else else

@ -10,6 +10,8 @@ void threadSendTCP::init(SyncQueue<_TCPSendInfo>* p_TCP_Info_queue, std::string
port = port_; port = port_;
qDebug() << "tcp ip:" << ip << "| tcp port:" << port; qDebug() << "tcp ip:" << ip << "| tcp port:" << port;
Local_TCP_Info_queue = p_TCP_Info_queue; Local_TCP_Info_queue = p_TCP_Info_queue;
} }
void threadSendTCP::start_work() void threadSendTCP::start_work()
{ {
@ -30,25 +32,26 @@ bool threadSendTCP::connectTCP() {
mySocket->abort(); mySocket->abort();
// 连接服务器 // 连接服务器
mySocket->connectToHost(ip, port); mySocket->connectToHost(ip, port);
if (!mySocket->waitForConnected(30000)) { if (!mySocket->waitForConnected(100)) {
qDebug() << "connect failed!"; qDebug() << "connect failed!";
return false; return false;
} }
qDebug() << "connect successfully!"; qDebug() << "connect successfully!";
return true; return true;
} }
void threadSendTCP::run() void threadSendTCP::run()
{ {
if (!connectTCP()) if (!connectTCP())
{
qDebug() << "TCP connect error!"; qDebug() << "TCP connect error!";
}
while (isLoop) { while (isLoop) {
_TCPSendInfo TCPSendInfo; _TCPSendInfo TCPSendInfo;
Local_TCP_Info_queue->take(TCPSendInfo); Local_TCP_Info_queue->take(TCPSendInfo);
num++; num++;
sendData(&TCPSendInfo, num); sendData(&TCPSendInfo, num);
//mySocket->write("Hello! here is tcp client!\n"); //mySocket->write("Hello! here is tcp client!\n");
//mySocket->flush(); //mySocket->flush();
} }
} }
@ -58,3 +61,4 @@ void threadSendTCP::sendData(_TCPSendInfo* TCPSendInfo, int Num) {
mySocket->write("\n"); mySocket->write("\n");
mySocket->flush(); mySocket->flush();
} }

@ -11,10 +11,15 @@ class _TCPSendInfo
{ {
public: public:
std::string pics_name; std::string pics_name;
std::string result;
std::string num;
_TCPSendInfo() _TCPSendInfo()
{ {
pics_name = ""; pics_name = "";
} }
}; };
@ -52,4 +57,5 @@ public:
SyncQueue<_TCPSendInfo>* Local_TCP_Info_queue; SyncQueue<_TCPSendInfo>* Local_TCP_Info_queue;
std::atomic_bool isLoop = { 0 }; std::atomic_bool isLoop = { 0 };
QTcpSocket* mySocket; QTcpSocket* mySocket;
}; };

Loading…
Cancel
Save