From fd494f2a03c1def294839caf01fb2d705e3a1877 Mon Sep 17 00:00:00 2001 From: luocai Date: Fri, 13 Dec 2024 16:57:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=A3=80=E6=B5=8B=E9=98=88?= =?UTF-8?q?=E5=80=BC=E8=AE=BE=E7=BD=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application.cpp | 49 +++++++++++-- Application.h | 16 ++++- CMakeLists.txt | 2 +- DeviceConnection.cpp | 32 ++++++--- DeviceConnection.h | 8 ++- qml/DeviceView.qml | 163 ++++++++++++++++++++++++++++++------------- qml/Main.qml | 2 + 7 files changed, 203 insertions(+), 69 deletions(-) diff --git a/Application.cpp b/Application.cpp index 1f90714..3c4af7a 100644 --- a/Application.cpp +++ b/Application.cpp @@ -220,7 +220,37 @@ void Application::setCurrentHelmetThreshold(int threshold) { emit currentHelmetThresholdChanged(); if (!m_device.expired()) { auto device = m_device.lock(); - device->updateHelmetThreshold(threshold); + device->updateDetectThreshold(m_currentHelmetThreshold, m_currentHeadThreshold, m_currentDetectFrameSize); + } + } +} + +int Application::currentHeadThreshold() const { + return m_currentHeadThreshold; +} + +void Application::setCurrentHeadThreshold(int threshold) { + if (m_currentHeadThreshold != threshold) { + m_currentHeadThreshold = threshold; + emit currentHeadThresholdChanged(); + if (!m_device.expired()) { + auto device = m_device.lock(); + device->updateDetectThreshold(m_currentHelmetThreshold, m_currentHeadThreshold, m_currentDetectFrameSize); + } + } +} + +int Application::currentDetectFrameSize() const { + return m_currentDetectFrameSize; +} + +void Application::setCurrentDetectFrameSize(int size) { + if (m_currentDetectFrameSize != size) { + m_currentDetectFrameSize = size; + emit currentDetectFrameSizeChanged(); + if (!m_device.expired()) { + auto device = m_device.lock(); + device->updateDetectThreshold(m_currentHelmetThreshold, m_currentHeadThreshold, m_currentDetectFrameSize); } } } @@ -246,8 +276,8 @@ void Application::connectToDevice(int index) { disconnect(device.get(), &DeviceConnection::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea); disconnect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea); disconnect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea); - disconnect(device.get(), &DeviceConnection::helmetThresholdChanged, this, - &Application::onDeviceHelmetThreshold); + disconnect(device.get(), &DeviceConnection::detectThresholdChanged, this, + &Application::onDeviceDetectThresholdChanged); disconnect(device.get(), &DeviceConnection::networkInfomationChanged, this, &Application::onDeviceNetworkInfomation); disconnect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware); @@ -272,7 +302,8 @@ void Application::connectToDevice(int index) { connect(device.get(), &DeviceConnection::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea); connect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea); connect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea); - connect(device.get(), &DeviceConnection::helmetThresholdChanged, this, &Application::onDeviceHelmetThreshold); + connect(device.get(), &DeviceConnection::detectThresholdChanged, this, + &Application::onDeviceDetectThresholdChanged); connect(device.get(), &DeviceConnection::networkInfomationChanged, this, &Application::onDeviceNetworkInfomation); connect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware); @@ -302,6 +333,8 @@ void Application::connectToDevice(int index) { m_currentDeviceFlip = info.flip; m_currentDeviceRotation = info.rotation; m_currentHelmetThreshold = info.helmetThreshold; + m_currentHeadThreshold = info.headThreshold; + m_currentDetectFrameSize = info.detectFrameSize; emit currentDeviceRotationChanged(); emit currentDeviceFlipChanged(); emit currentOpenDoorAreaPointsChanged(); @@ -312,6 +345,8 @@ void Application::connectToDevice(int index) { emit currentAntiClipAreaEnabledChanged(); emit currentAntiClipSensitivityChanged(); emit currentHelmetThresholdChanged(); + emit currentHeadThresholdChanged(); + emit currentDetectFrameSizeChanged(); emit currentNetworkInfomationChanged(); } emit currentFirmwareChanged(); @@ -378,8 +413,10 @@ void Application::onDeviceAntiClipArea(bool enabled, const QList &point setCurrentAntiClipSensitivity(sensitivity); } -void Application::onDeviceHelmetThreshold(int threshold) { - setCurrentHelmetThreshold(threshold); +void Application::onDeviceDetectThresholdChanged(int helmetThreshold, int headThreshold, int detectFrameSize) { + setCurrentHelmetThreshold(helmetThreshold); + setCurrentHeadThreshold(headThreshold); + setCurrentDetectFrameSize(detectFrameSize); } void Application::onDeviceNetworkInfomation(const NetworkInfomation &info) { diff --git a/Application.h b/Application.h index 59e961e..b7f3058 100644 --- a/Application.h +++ b/Application.h @@ -37,6 +37,10 @@ class Application : public QObject { Q_PROPERTY(int currentAntiClipSensitivity READ currentAntiClipSensitivity WRITE setCurrentAntiClipSensitivity NOTIFY currentAntiClipSensitivityChanged) Q_PROPERTY(int currentHelmetThreshold READ currentHelmetThreshold WRITE setCurrentHelmetThreshold NOTIFY currentHelmetThresholdChanged) + Q_PROPERTY(int currentHeadThreshold READ currentHeadThreshold WRITE setCurrentHeadThreshold NOTIFY + currentHeadThresholdChanged) + Q_PROPERTY(int currentDetectFrameSize READ currentDetectFrameSize WRITE setCurrentDetectFrameSize NOTIFY + currentDetectFrameSizeChanged) Q_PROPERTY(QList currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged) Q_PROPERTY( @@ -82,6 +86,12 @@ public: int currentHelmetThreshold() const; void setCurrentHelmetThreshold(int threshold); + int currentHeadThreshold() const; + void setCurrentHeadThreshold(int threshold); + + int currentDetectFrameSize() const; + void setCurrentDetectFrameSize(int size); + Q_INVOKABLE void updateOpenDoorAreaPoints(const QList &points); Q_INVOKABLE void updateAntiClipAreaPoints(const QList &points); Q_INVOKABLE void updateShieldedAreaPoints(const QList &points); @@ -105,6 +115,8 @@ signals: void currentAntiClipAreaEnabledChanged(); void currentAntiClipSensitivityChanged(); void currentHelmetThresholdChanged(); + void currentDetectFrameSizeChanged(); + void currentHeadThresholdChanged(); void currentNetworkInfomationChanged(); void currentFirmwareChanged(); void currentDeviceConnectedChanged(); @@ -120,7 +132,7 @@ protected: void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList &points); void onDeviceShieldedArea(bool enabled, const QList &points); void onDeviceAntiClipArea(bool enabled, const QList &points, int sensitivity); - void onDeviceHelmetThreshold(int threshold); + void onDeviceDetectThresholdChanged(int helmetThreshold, int headThreshold, int detectFrameSize); void onDeviceNetworkInfomation(const NetworkInfomation &info); void onDeviceFirmware(const QString &firmware); void onDeviceConnected(); @@ -148,6 +160,8 @@ private: bool m_currentDeviceFlip = false; int m_currentDeviceRotation = 0; int m_currentHelmetThreshold = 1; + int m_currentHeadThreshold = 2; + int m_currentDetectFrameSize = 3; }; #endif // APPLICATION_H diff --git a/CMakeLists.txt b/CMakeLists.txt index b4daca3..01733a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.16) -project(AntiClipSettings VERSION 1.7 LANGUAGES C CXX) +project(AntiClipSettings VERSION 1.8 LANGUAGES C CXX) set(APPLICATION_NAME "视觉防夹设备上位机工具") set(CMAKE_CXX_STANDARD 17) diff --git a/DeviceConnection.cpp b/DeviceConnection.cpp index a05729a..00e2efe 100644 --- a/DeviceConnection.cpp +++ b/DeviceConnection.cpp @@ -240,16 +240,24 @@ void DeviceConnection::updateAntiClipAreaPoints(bool enabled, const QList DeviceConnection::updateHelmetThreshold(int threshold) { - constexpr auto command = "thresholdwithhat_setdata"; +QFuture DeviceConnection::updateDetectThreshold(int helmetThreshold, int headThreshold, int detectFrameSize) { + constexpr auto command = "headdetectparam_setdata"; Task task; task.command = command; - task.task = [this, threshold, command]() { + task.task = [this, helmetThreshold, headThreshold, detectFrameSize, command]() { boost::json::object request; request["func"] = command; request["deviceid"] = "0"; boost::json::object data; - data["value"] = threshold; + if (headThreshold >= 0) { + data["headthreshold"] = headThreshold; + } + if (helmetThreshold >= 0) { + data["hatthreshold"] = helmetThreshold; + } + if (detectFrameSize >= 0) { + data["detectframenum"] = detectFrameSize; + } request["data"] = std::move(data); auto text = boost::json::serialize(request); m_commandSocket->write(text.data(), text.size()); @@ -263,8 +271,8 @@ QFuture DeviceConnection::updateHelmetThreshold(int threshold) { return ret; } -void DeviceConnection::requestHelmetThreshold() { - constexpr auto command = "thresholdwithhat_getdata"; +void DeviceConnection::requestHeadDetectThreshold() { + constexpr auto command = "headdetectparam_getdata"; Task task; task.command = command; task.task = [this, command]() { @@ -739,11 +747,13 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const requestVideoInformation(); } else if (function == "a12factory_setdata") { LOG(info) << "device factory reset"; - } else if (function == "thresholdwithhat_getdata") { + } else if (function == "headdetectparam_getdata") { auto &data = reply.at("data").as_object(); - auto &value = data.at("value").as_int64(); - m_infomation.helmetThreshold = value; - emit helmetThresholdChanged(m_infomation.helmetThreshold); + m_infomation.helmetThreshold = data.at("hatthreshold").as_int64(); + m_infomation.headThreshold = data.at("headthreshold").as_int64(); + m_infomation.detectFrameSize = data.at("detectframenum").as_int64(); + emit detectThresholdChanged(m_infomation.helmetThreshold, m_infomation.headThreshold, + m_infomation.detectFrameSize); } else if (function == "thresholdwithhat_setdata") { if ((task != nullptr) && (task->command.toStdString() == function)) { if (task->timeoutTimer) { @@ -769,7 +779,7 @@ void DeviceConnection::onConnected() { requestAntiClipArea(); requestNetworkInfomation(); requestVideoInformation(); - requestHelmetThreshold(); + requestHeadDetectThreshold(); emit connected(); m_heartbeatTimerId = startTimer(2500); if (m_otaProgress == 99) { diff --git a/DeviceConnection.h b/DeviceConnection.h index af15c3c..b3d6c5e 100644 --- a/DeviceConnection.h +++ b/DeviceConnection.h @@ -49,6 +49,8 @@ public: bool antiClipAreaEnabled; int antiClipSensitivity = 1; int helmetThreshold = 1; + int headThreshold = 1; + int detectFrameSize = 1; }; Q_ENUM(AreaWay) @@ -72,8 +74,8 @@ public: void updateAntiClipAreaPoints(bool enabled, const QList &points, int sensitivity); void requestResolution(Resolution resolution); void requestNetworkInfomation(); - QFuture updateHelmetThreshold(int threshold); - void requestHelmetThreshold(); + QFuture updateDetectThreshold(int helmetThreshold, int headThreshold, int detectFrameSize); + void requestHeadDetectThreshold(); QFuture updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway, const QString &dns); void requestVersion(); @@ -101,7 +103,7 @@ signals: void antiClipAreaChanged(bool enabled, const QList &points, int sensitivity); void rotationChanged(int rotation); void flipChanged(bool flip); - void helmetThresholdChanged(int threshold); + void detectThresholdChanged(int helmetThreshold, int headThreshold, int detectFrameSize); void networkInfomationChanged(const NetworkInfomation &info); void firmwareChanged(const QString &firmware); void otaProgressChanged(bool status, int progress, const QString &message); diff --git a/qml/DeviceView.qml b/qml/DeviceView.qml index d3f8977..1fc36f3 100644 --- a/qml/DeviceView.qml +++ b/qml/DeviceView.qml @@ -18,6 +18,8 @@ Item { property bool antiClipAreaEnabled: false property int antiClipSensitivity: 1 property alias helmetThreshold: helmetInput.text + property alias headThreshold: headInput.text + property alias detectFrameSize: detectFrameInput.text property alias flip: flipSwitch.checked property alias videoRotation: rotateComboBox.currentIndex @@ -248,13 +250,12 @@ Item { anchors.left: parent.left anchors.right: parent.right anchors.bottom: parent.bottom - columns: 6 + columns: 2 Label { text: qsTr("图像: ") } Row { enabled: root.enabled - Layout.columnSpan: 5 Label { anchors.verticalCenter: parent.verticalCenter text: qsTr("旋转") @@ -282,9 +283,9 @@ Item { Label { text: qsTr("开门区域: ") } + Row { enabled: root.enabled - Layout.columnSpan: 5 RadioButton { text: "关闭" checked: App.currentOpenDoorAreaWay ==DeviceConnection.Diabled @@ -308,63 +309,131 @@ Item { } } + Label { + Layout.alignment: Qt.AlignTop + Layout.topMargin: 14 + text: qsTr("防夹区域: ") + } - Label {text: qsTr("防夹区域: ")} - Row { - enabled: root.enabled - Layout.columnSpan: 1 - RadioButton { - text: "关闭" - checked: !App.currentAntiClipAreaEnabled - onToggled: { - App.currentAntiClipAreaEnabled=false + Flow{ + Layout.fillHeight: true + Layout.fillWidth: true + RowLayout { + enabled: root.enabled + RadioButton { + text: "关闭" + checked: !App.currentAntiClipAreaEnabled + onToggled: { + App.currentAntiClipAreaEnabled=false + } + + } + RadioButton { + text: "四边形" + checked: App.currentAntiClipAreaEnabled + onToggled: { + App.currentAntiClipAreaEnabled=true + } + Layout.rightMargin: 20 } } - RadioButton { - text: "四边形" - checked: App.currentAntiClipAreaEnabled - onToggled: { - App.currentAntiClipAreaEnabled=true + RowLayout { + Label { text: qsTr("灵敏度: ") + Layout.alignment: Qt.AlignRight + } + ComboBox { + id: antiClipSensitivityComboBox + enabled: root.enabled + implicitWidth: 60 + Layout.alignment: Qt.AlignLeft + model: [1,2,3,4,5] + currentIndex: root.antiClipSensitivity-1 + onCurrentIndexChanged: { + App.currentAntiClipSensitivity = antiClipSensitivityComboBox.currentIndex+1 + } + Layout.rightMargin: 20 + } + } + RowLayout { + Label { text: qsTr("安全帽阈值: ") + Layout.alignment: Qt.AlignRight + } + TextField { + id: helmetInput + enabled: root.enabled + implicitWidth: 60 + Layout.alignment: Qt.AlignLeft + selectByMouse: true + ToolTip.visible: helmetInput.hovered + ToolTip.text: "阈值范围 0-300" + validator: IntValidator { + bottom: 0 + top: 300 + } + onAccepted: { + if(App.currentHelmetThreshold !== parseInt(helmetInput.text)){ + App.currentHelmetThreshold= parseInt(helmetInput.text) + window.showSuccess("设置成功",2500) + } + } + Layout.rightMargin: 20 } } - } - Label { text: qsTr("灵敏度: ") - Layout.alignment: Qt.AlignRight - } - ComboBox { - id: antiClipSensitivityComboBox - enabled: root.enabled - implicitWidth: 60 - Layout.alignment: Qt.AlignLeft - model: [1,2,3,4,5] - currentIndex: root.antiClipSensitivity-1 - onCurrentIndexChanged: { - App.currentAntiClipSensitivity = antiClipSensitivityComboBox.currentIndex+1 + RowLayout { + Label { text: qsTr("头肩阈值: ") + Layout.alignment: Qt.AlignRight + } + TextField { + id: headInput + enabled: root.enabled + implicitWidth: 60 + Layout.alignment: Qt.AlignLeft + selectByMouse: true + ToolTip.visible: headInput.hovered + ToolTip.text: "阈值范围 0-300" + validator: IntValidator { + bottom: 0 + top: 300 + } + onAccepted: { + if(App.currentHeadThreshold !== parseInt(headInput.text)){ + App.currentHeadThreshold= parseInt(headInput.text) + window.showSuccess("设置成功",2500) + } + } + Layout.rightMargin: 20 + } } - } - Label { text: qsTr("安全帽阈值: ") - Layout.alignment: Qt.AlignRight - } - TextField { - id: helmetInput - enabled: root.enabled - implicitWidth: 60 - Layout.alignment: Qt.AlignLeft - validator: IntValidator { - bottom: 0 - top: 300 - } - onAccepted: { - if(App.currentHelmetThreshold !== parseInt(helmetInput.text)){ - App.currentHelmetThreshold= parseInt(helmetInput.text) - window.showSuccess("设置成功",2500) + RowLayout { + Label { text: qsTr("识别帧数: ") + Layout.alignment: Qt.AlignRight + } + TextField { + id: detectFrameInput + enabled: root.enabled + implicitWidth: 60 + Layout.alignment: Qt.AlignLeft + selectByMouse: true + ToolTip.visible: detectFrameInput.hovered + ToolTip.text: "帧数范围 0-30" + validator: IntValidator { + bottom: 0 + top: 30 + } + onAccepted: { + if(App.currentDetectFrameSize !== parseInt(detectFrameInput.text)){ + App.currentDetectFrameSize= parseInt(detectFrameInput.text) + window.showSuccess("设置成功",2500) + } + } } } } + Label {text: qsTr("屏蔽区域: ")} Row { id: shieldedRow diff --git a/qml/Main.qml b/qml/Main.qml index 1074da3..196abe3 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -122,6 +122,8 @@ ApplicationWindow { antiClipSensitivity: App.currentAntiClipSensitivity antiClipAreaPoints: App.currentAntiClipAreaPoints helmetThreshold: App.currentHelmetThreshold + headThreshold: App.currentHeadThreshold + detectFrameSize: App.currentDetectFrameSize flip: App.currentDeviceFlip videoRotation: App.currentDeviceRotation }