feat: 改写GIGE协议

This commit is contained in:
2026-01-16 18:07:52 +08:00
parent ff4a4cabc8
commit 8b07397b5b
11 changed files with 321 additions and 97 deletions

View File

@@ -15,6 +15,7 @@
#include <QSpinBox>
#include <QSlider>
#include <QTimer>
#include <QThread>
#include <QListWidget>
#include <QDebug>
#include <QFileDialog>
@@ -48,9 +49,12 @@ MainWindow::MainWindow(QWidget *parent)
, m_autoSaveOnNextFrame(false)
, m_currentPointCloud(new pcl::PointCloud<pcl::PointXYZ>())
, m_currentFrameId(0)
, m_frameCount(0)
, m_totalFrameCount(0)
, m_currentFps(0.0)
, m_depthFrameCount(0)
, m_totalDepthFrameCount(0)
, m_currentDepthFps(0.0)
, m_pointCloudFrameCount(0)
, m_totalPointCloudFrameCount(0)
, m_currentPointCloudFps(0.0)
{
setupUI();
setupConnections();
@@ -74,6 +78,15 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow()
{
// 在退出前发送STOP命令停止下位机采集
if (m_isConnected && m_networkManager) {
qDebug() << "程序退出发送STOP命令到下位机";
m_networkManager->sendStopCommand();
// 等待一小段时间确保命令发送完成
QThread::msleep(100);
}
saveSettings();
}
@@ -427,17 +440,20 @@ void MainWindow::setupUI()
QGroupBox *statsGroup = new QGroupBox("统计信息", m_controlPanel);
QVBoxLayout *statsLayout = new QVBoxLayout(statsGroup);
m_fpsLabel = new QLabel("帧率: 0.0 fps", statsGroup);
m_depthFpsLabel = new QLabel("红外图帧率: 0.0 fps", statsGroup);
m_pointCloudFpsLabel = new QLabel("点云帧率: 0.0 fps", statsGroup);
m_resolutionLabel = new QLabel("分辨率: 1224 x 1024", statsGroup);
m_queueLabel = new QLabel("接收帧数: 0", statsGroup);
// 设置统计标签样式 - 移除固定颜色以支持深色模式
QString statsLabelStyle = "QLabel { font-size: 10pt; padding: 4px; }";
m_fpsLabel->setStyleSheet(statsLabelStyle);
m_depthFpsLabel->setStyleSheet(statsLabelStyle);
m_pointCloudFpsLabel->setStyleSheet(statsLabelStyle);
m_resolutionLabel->setStyleSheet(statsLabelStyle);
m_queueLabel->setStyleSheet(statsLabelStyle);
statsLayout->addWidget(m_fpsLabel);
statsLayout->addWidget(m_depthFpsLabel);
statsLayout->addWidget(m_pointCloudFpsLabel);
statsLayout->addWidget(m_resolutionLabel);
statsLayout->addWidget(m_queueLabel);
@@ -472,6 +488,7 @@ void MainWindow::setupConnections()
// GVSP数据信号连接从NetworkManager
connect(m_networkManager.get(), &NetworkManager::imageReceived, this, &MainWindow::onImageReceived);
connect(m_networkManager.get(), &NetworkManager::depthDataReceived, this, &MainWindow::onDepthDataReceived);
connect(m_networkManager.get(), &NetworkManager::pointCloudDataReceived, this, &MainWindow::onPointCloudDataReceived);
// 点云处理信号连接
connect(m_pointCloudProcessor.get(), &PointCloudProcessor::pointCloudReady, this, &MainWindow::onPointCloudReady);
@@ -712,26 +729,26 @@ void MainWindow::onImageReceived(const QImage &image, uint32_t blockId)
m_currentImage = image;
m_currentFrameId = blockId;
// 计算FPS和累计帧数
m_frameCount++;
m_totalFrameCount++;
// 计算深度图FPS和累计帧数
m_depthFrameCount++;
m_totalDepthFrameCount++;
QDateTime currentTime = QDateTime::currentDateTime();
if (m_lastFrameTime.isValid()) {
qint64 elapsed = m_lastFrameTime.msecsTo(currentTime);
if (m_lastDepthFrameTime.isValid()) {
qint64 elapsed = m_lastDepthFrameTime.msecsTo(currentTime);
if (elapsed >= 1000) { // 每秒更新一次FPS
m_currentFps = (m_frameCount * 1000.0) / elapsed;
m_frameCount = 0;
m_lastFrameTime = currentTime;
m_currentDepthFps = (m_depthFrameCount * 1000.0) / elapsed;
m_depthFrameCount = 0;
m_lastDepthFrameTime = currentTime;
updateStatistics();
}
} else {
m_lastFrameTime = currentTime;
m_lastDepthFrameTime = currentTime;
}
// 将图像显示在UI上
// 将图像显示在UI上(使用快速缩放)
if (m_imageDisplay) {
QPixmap pixmap = QPixmap::fromImage(image);
m_imageDisplay->setPixmap(pixmap.scaled(m_imageDisplay->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
m_imageDisplay->setPixmap(pixmap.scaled(m_imageDisplay->size(), Qt::KeepAspectRatio, Qt::FastTransformation));
}
}
@@ -745,6 +762,16 @@ void MainWindow::onDepthDataReceived(const QByteArray &depthData, uint32_t block
m_pointCloudProcessor->processDepthData(depthData, blockId);
}
void MainWindow::onPointCloudDataReceived(const QByteArray &cloudData, uint32_t blockId)
{
// qDebug() << "[MainWindow] Point cloud data received: Block" << blockId << "Size:" << cloudData.size() << "bytes";
// 使用QtConcurrent在后台线程处理点云数据
QtConcurrent::run([this, cloudData, blockId]() {
m_pointCloudProcessor->processPointCloudData(cloudData, blockId);
});
}
void MainWindow::onPointCloudReady(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, uint32_t blockId)
{
// 注释掉频繁的日志输出
@@ -753,6 +780,22 @@ void MainWindow::onPointCloudReady(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, ui
// 保存当前点云用于拍照
m_currentPointCloud = cloud;
// 计算点云FPS和累计帧数
m_pointCloudFrameCount++;
m_totalPointCloudFrameCount++;
QDateTime currentTime = QDateTime::currentDateTime();
if (m_lastPointCloudFrameTime.isValid()) {
qint64 elapsed = m_lastPointCloudFrameTime.msecsTo(currentTime);
if (elapsed >= 1000) { // 每秒更新一次FPS
m_currentPointCloudFps = (m_pointCloudFrameCount * 1000.0) / elapsed;
m_pointCloudFrameCount = 0;
m_lastPointCloudFrameTime = currentTime;
updateStatistics();
}
} else {
m_lastPointCloudFrameTime = currentTime;
}
// 更新点云显示
if (m_pointCloudWidget) {
m_pointCloudWidget->updatePointCloud(cloud);
@@ -1093,14 +1136,21 @@ void MainWindow::onSaveLogClicked()
// ========== 统计信息更新 ==========
void MainWindow::updateStatistics()
{
// 更新帧率
if (m_fpsLabel) {
m_fpsLabel->setText(QString("帧率: %1 fps").arg(m_currentFps, 0, 'f', 1));
// 更新红外图帧率
if (m_depthFpsLabel) {
m_depthFpsLabel->setText(QString("红外图帧率: %1 fps").arg(m_currentDepthFps, 0, 'f', 1));
}
// 更新接收帧数(显示累计总数)
// 更新点云帧率
if (m_pointCloudFpsLabel) {
m_pointCloudFpsLabel->setText(QString("点云帧率: %1 fps").arg(m_currentPointCloudFps, 0, 'f', 1));
}
// 更新接收帧数(显示红外图和点云的累计总数)
if (m_queueLabel) {
m_queueLabel->setText(QString("接收帧数: %1").arg(m_totalFrameCount));
m_queueLabel->setText(QString("接收帧数: 红外%1 点云%2")
.arg(m_totalDepthFrameCount)
.arg(m_totalPointCloudFrameCount));
}
}

View File

@@ -52,6 +52,7 @@ private slots:
// GVSP数据处理槽函数
void onImageReceived(const QImage &image, uint32_t blockId);
void onDepthDataReceived(const QByteArray &depthData, uint32_t blockId);
void onPointCloudDataReceived(const QByteArray &cloudData, uint32_t blockId);
void onPointCloudReady(pcl::PointCloud<pcl::PointXYZ>::Ptr cloud, uint32_t blockId);
// 设备扫描槽函数
@@ -140,7 +141,8 @@ private:
QListWidget *m_deviceList;
// 统计信息控件
QLabel *m_fpsLabel;
QLabel *m_depthFpsLabel;
QLabel *m_pointCloudFpsLabel;
QLabel *m_resolutionLabel;
QLabel *m_queueLabel;
@@ -149,11 +151,17 @@ private:
QPushButton *m_clearLogBtn;
QPushButton *m_saveLogBtn;
// 统计数据
QDateTime m_lastFrameTime;
int m_frameCount;
int m_totalFrameCount;
double m_currentFps;
// 统计数据 - 深度图
QDateTime m_lastDepthFrameTime;
int m_depthFrameCount;
int m_totalDepthFrameCount;
double m_currentDepthFps;
// 统计数据 - 点云
QDateTime m_lastPointCloudFrameTime;
int m_pointCloudFrameCount;
int m_totalPointCloudFrameCount;
double m_currentPointCloudFps;
};
#endif // MAINWINDOW_H

View File

@@ -224,11 +224,11 @@ void PointCloudGLWidget::updatePointCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr cl
// 添加调试日志
static int updateCount = 0;
if (updateCount < 3 || updateCount % 100 == 0) {
qDebug() << "[PointCloudGLWidget] Update" << updateCount << "- Points:" << m_pointCount
<< "Total cloud size:" << cloud->size();
qDebug() << " X range:" << minX << "to" << maxX;
qDebug() << " Y range:" << minY << "to" << maxY;
qDebug() << " Z range:" << minZ << "to" << maxZ;
// qDebug() << "[PointCloudGLWidget] Update" << updateCount << "- Points:" << m_pointCount
// << "Total cloud size:" << cloud->size();
// qDebug() << " X range:" << minX << "to" << maxX;
// qDebug() << " Y range:" << minY << "to" << maxY;
// qDebug() << " Z range:" << minZ << "to" << maxZ;
}
updateCount++;