tcp传图片名

main
seiyu 10 months ago
parent 215acc558b
commit fc8f54c7d3

@ -7,7 +7,7 @@
extern bool g_debug_mode; //相机调试模式,工作模式必须停止状态才能打开
extern SingleCamInfoStruct SingleCamInfo[NumberOfSupportedCameras];
extern SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue;
extern PLCDevice * m_PLCDevice;
extern PLCDevice* m_PLCDevice;
inline void LossCallBackfunction(unsigned int pData, void* pUser){
try{

@ -133,15 +133,15 @@
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<LanguageStandard>stdcpp14</LanguageStandard>
<Optimization>Disabled</Optimization>
<Optimization>MaxSpeed</Optimization>
<SupportJustMyCode>false</SupportJustMyCode>
<DisableSpecificWarnings>4819;%(DisableSpecificWarnings)</DisableSpecificWarnings>
</ClCompile>
<Link>
<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>true</GenerateDebugInformation>
<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;Ws2_32.lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</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>
@ -349,6 +349,7 @@
<ClCompile Include="SyncQueue.cpp" />
<ClCompile Include="threadReceive.cpp" />
<ClCompile Include="threadSend.cpp" />
<ClCompile Include="threadSendTCP.cpp" />
<ClCompile Include="tinyxml2.cpp" />
<ClCompile Include="workthread.cpp" />
</ItemGroup>
@ -394,6 +395,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="FtpManager.h" />
<ClInclude Include="threadSendTCP.h" />
<ClInclude Include="tinyxml2.h" />
<CustomBuild Include="threadReceive.h">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>

@ -257,6 +257,9 @@
<ClCompile Include="tinyxml2.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="threadSendTCP.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="cigarette.h">
@ -420,5 +423,8 @@
<ClInclude Include="FtpManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="threadSendTCP.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

@ -0,0 +1 @@
8<EFBFBD><EFBFBD><EFBFBD>“ם׳x;¶i‡Bˆ׃2@%^/|׳y׃<>5 *•„¢‏)*3Hgkָ<6B>¬ץ<C2AC><D7A5>¼g EdֿQ₪¦+SBt<42>RRֱ~ףMצ£X¨Tֹ2÷ּO'EֲָS<D6B8>1…,¬ִֵl תgZֲײ=wµ†xI<78>ׂKָ„¿ƒ,Rb?ױ¶ׂi<D782>«<EFBFBD>% :YCm<43>ע†<D7A2>¬n}ב

@ -59,10 +59,12 @@ SyncQueue<cv::Mat> *g_debug_queue[NumberOfSupportedCameras]; //
#ifdef __UDPSend
SyncQueue<_UDPSendInfo>* UDP_Info_queue;
#endif
#ifdef __TCPSend
SyncQueue<_TCPSendInfo>* TCP_Info_queue;
#endif
bool flag = false;
#ifdef __ExportData
SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue;
#ifdef __ExportData
ExportDataThread exportDataThread;
#endif
@ -138,12 +140,16 @@ Cigarette::Cigarette(QWidget *parent)
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";
#ifdef __UDPSend
UDP_Info_queue = new SyncQueue<_UDPSendInfo>(Queue_Size);
UDP_Info_queue->name = "UDP Info queue";
#endif
#ifdef __TCPSend
TCP_Info_queue = new SyncQueue<_TCPSendInfo>(Queue_Size);
TCP_Info_queue->name = "TCP Info queue";
#endif
#ifdef __ExportData
export_XMLData_Info_queue = new SyncQueue<_XMLExportDataInfo>(Queue_Size);
export_XMLData_Info_queue->name = "Export Data Info queue";
@ -262,6 +268,13 @@ Cigarette::Cigarette(QWidget *parent)
rThread->start_work();
#endif
#ifdef __TCPSend
std::string serverIp = "192.168.1.120";
int serverPort = 8888;
tcpSendThread.init(TCP_Info_queue, serverIp, serverPort);
tcpSendThread.start_work();
#endif
#ifdef __ExportData
exportDataThread.init();
connect(this, &Cigarette::sendMsgToExportData, &exportDataThread, &ExportDataThread::EDrecMsgFromCigarette);
@ -359,7 +372,7 @@ Cigarette::Cigarette(QWidget *parent)
}
else if (alarm_info.alarm_code == 0) {
ui.label_alarm->setStyleSheet(tr("background-color: rgb(0, 170, 0);"));
ui.label_alarm->setText(QStringLiteral("无报警"));
ui.label_alarm->setText(QStringLiteral("ÎÞ±¨¾¯"));
}
#ifdef __UDPSend
QString str;
@ -406,8 +419,10 @@ Cigarette::Cigarette(QWidget *parent)
m_delay = new QTimer(this);//»»°à·ÀÁ¬»÷
connect(m_delay, SIGNAL(timeout()), this, SLOT(enable_shift()));
#ifdef __UDPSend
m_sendMsg_delay = new QTimer(this);
connect(m_sendMsg_delay, SIGNAL(timeout()), this, SLOT(sendLatestData()));
#endif
m_op_delay = new QTimer(this);
connect(m_op_delay, SIGNAL(timeout()), this, SLOT(op_timeout()));
@ -629,8 +644,10 @@ void Cigarette::pause_work()
label_reslut_mat[i]->setVisible(false);
}
#ifdef __UDPSend
m_sendMsg_delay->setSingleShot(true);
m_sendMsg_delay->start(1000);
#endif
}
void Cigarette::Exit()
@ -663,6 +680,10 @@ void Cigarette::Exit()
delete rThread;
#endif
#ifdef __TCPSend
tcpSendThread.stop();
#endif
#ifdef __ExportData
exportDataThread.stop();
// delete export_Data_Info_queue;
@ -897,7 +918,7 @@ void Cigarette::OnRotateReleasedHub(int Num)//
{
QString str = "Start to rotate picture " + QString::number(90 * ((rotationAngle[Num] + 1) % 4)) + " degrees of camera " + QString::number(Num) + ".";
emit sengMsgToClog(str);
if(isNeedRotate[Num] == true)
if( isNeedRotate[Num] == true)
{
rotationAngle[Num] = (rotationAngle[Num] + 1) % 4;
save_rotate_message();
@ -1074,7 +1095,7 @@ void Cigarette::OnDBClickHub(int Num_Cnt)
display_lable_info[Num][Cnt].height
);
rotate_mat[Num]->setGeometry(
rotate_info[Num].x,
rotate_info[Num].x,
rotate_info[Num].y,
rotate_info[Num].width,
rotate_info[Num].height

@ -29,6 +29,7 @@
#include "Logthread.h"
#include "threadSend.h"
#include "threadReceive.h"
#include "threadSendTCP.h"
#include "Cleanthread.h"
#include <QtWidgets/QMainWindow>
@ -206,6 +207,10 @@ public:
threadSend sThread;
threadReceive *rThread;
#endif
#ifdef __TCPSend
private:
threadSendTCP tcpSendThread;
#endif
public slots:
void CleanThreadStartAuto();
#ifdef __UDPSend

@ -7,7 +7,8 @@
#include "QtCore\qdatetime.h"
//#define __DEBUG //debug信息输出功能
#define __UDPSend //网络发送功能
//#define __UDPSend //网络发送功能
#define __TCPSend // TCP发送
#define USB_BASLER_NEW_FW //使用basler定制固件
//#define IMM_PROCESS //拍照后立马处理,不等校验信号
//#define IMM_FEED_BACK //处理完后立马反馈,不等校验信号
@ -20,7 +21,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

@ -12,7 +12,7 @@
#include <opencv2/opencv.hpp>
#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; //ͼÏñ±£´æ¶ÓÁÐ
class SaveThread : public QThread
{

@ -64,7 +64,6 @@ void threadSend::run()
void threadSend::sendData(_UDPSendInfo *UDPSendInfo,int port)
{
QString res = QString("%1_%2_%3")
.arg(QString::number(UDPSendInfo->FrameID))
.arg(UDPSendInfo->JD)

@ -0,0 +1,61 @@
#include "threadSendTCP.h"
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <stdio.h>
#include <qtcpsocket.h>
#pragma comment(lib, "ws2_32.lib")
void threadSendTCP::init(SyncQueue<_TCPSendInfo>* p_TCP_Info_queue, std::string ip_, int port_) {
ip = QString::fromStdString(ip_);
port = port_;
qDebug() << "tcp ip:" << ip << "| tcp port:" << port;
Local_TCP_Info_queue = p_TCP_Info_queue;
}
void threadSendTCP::start_work()
{
//start(HighestPriority);
start();
}
void threadSendTCP::stop()
{
isLoop = false;
// wait();
delete mySocket;
}
bool threadSendTCP::connectTCP() {
mySocket = new QTcpSocket();
// 取消已有的连接
mySocket->abort();
// 连接服务器
mySocket->connectToHost(ip, port);
if (!mySocket->waitForConnected(30000)) {
qDebug() << "connect failed!";
return false;
}
qDebug() << "connect successfully!";
return true;
}
void threadSendTCP::run()
{
if (!connectTCP())
qDebug() << "TCP connect error!";
while (isLoop) {
_TCPSendInfo TCPSendInfo;
Local_TCP_Info_queue->take(TCPSendInfo);
num++;
sendData(&TCPSendInfo, num);
//mySocket->write("Hello! here is tcp client!\n");
//mySocket->flush();
}
}
void threadSendTCP::sendData(_TCPSendInfo* TCPSendInfo, int Num) {
std::string fileName = TCPSendInfo->pics_name + ", " + QString::number(Num).toStdString();
mySocket->write(fileName.c_str());
mySocket->write("\n");
mySocket->flush();
}

@ -0,0 +1,55 @@
#pragma once
#include <QDebug>
#include <QDateTime>
#include <iostream>
#include <QThread>
#include <qtcpsocket.h>
#include "common.h"
#include "SyncQueue.h"
class _TCPSendInfo
{
public:
std::string pics_name;
_TCPSendInfo()
{
pics_name = "";
}
};
class threadSendTCP : public QThread {
public:
QString ip;
int port;
int num = 0;
threadSendTCP(QObject* o = nullptr) :QThread(o)
{
isLoop = true;
}
~threadSendTCP()
{
stop();
_TCPSendInfo TCPSendInfo;
Local_TCP_Info_queue->put(TCPSendInfo);
quit();
wait();
}
void stop();
bool connectTCP();
protected:
void run();
public:
void init(SyncQueue<_TCPSendInfo>* p_TCP_Info_queue, std::string ip_, int port_);
void start_work();
void sendData(_TCPSendInfo* TCPSendInfo, int Num);
public:
SyncQueue<_TCPSendInfo>* Local_TCP_Info_queue;
std::atomic_bool isLoop = { 0 };
QTcpSocket *mySocket;
};

@ -21,6 +21,9 @@ extern SyncQueue<std::pair<int, cv::Mat>>* g_image_queue[NumberOfSupportedCamera
#ifdef __UDPSend
extern SyncQueue<_UDPSendInfo>* UDP_Info_queue;
#endif
#ifdef __TCPSend
extern SyncQueue<_TCPSendInfo>* TCP_Info_queue;
#endif
#ifdef __ExportData
extern ExportDataThread exportDataThread;
#endif
@ -78,7 +81,6 @@ void WorkThread::run()
#endif
}
QDateTime now_ts = QDateTime::currentDateTime();
std::pair<int, cv::Mat> element;
local_g_image_queue->take(element);
@ -90,6 +92,10 @@ void WorkThread::run()
UDPSendInfo.FrameID = info_frame;
UDPSendInfo.index = local_camera_number;
#endif
#ifdef __TCPSend
_TCPSendInfo TCPSendInfo;
#endif
if (!image.data)
{
continue; //ͼÏñΪ¿Õ£¬Ìø¹ý
@ -176,6 +182,10 @@ void WorkThread::run()
"#" + "_" + QString::number(index + 1) + ".jpg";
std::string filename = file_name.toLocal8Bit().constData();
g_save_queue->put(std::make_pair(filename, m));
#ifdef __TCPSend
TCPSendInfo.pics_name = filename;
TCP_Info_queue->put(TCPSendInfo);
#endif
}
}
@ -244,7 +254,10 @@ void WorkThread::run()
"#" + "_" + QString::number(index + 1) + "_" + ng_reason_maps[ngReason] +
".jpg";
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
#ifdef __TCPSend
TCPSendInfo.pics_name = file_name.toLocal8Bit().constData();
TCP_Info_queue->put(TCPSendInfo);
#endif
m = vec_out[index].clone();
file_name = g_conf_path.save_pics_path + "/ng_result/" +
now_ts.toString("yyyy-MM-dd") + "/"
@ -258,6 +271,11 @@ void WorkThread::run()
".jpg";
//g_save_queue->put(std::make_pair(file_name.toStdString(), m));
g_save_queue->put(std::make_pair(file_name.toLocal8Bit().constData(), m));
#ifdef __TCPSend
TCPSendInfo.pics_name = file_name.toLocal8Bit().constData();
TCP_Info_queue->put(TCPSendInfo);
#endif
}
}
}

Loading…
Cancel
Save