实现检测阈值设置。

This commit is contained in:
luocai 2024-12-13 16:57:00 +08:00
parent dbe7c1a64e
commit fd494f2a03
7 changed files with 203 additions and 69 deletions

View File

@ -220,7 +220,37 @@ void Application::setCurrentHelmetThreshold(int threshold) {
emit currentHelmetThresholdChanged(); emit currentHelmetThresholdChanged();
if (!m_device.expired()) { if (!m_device.expired()) {
auto device = m_device.lock(); 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::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea);
disconnect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea); disconnect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea);
disconnect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea); disconnect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea);
disconnect(device.get(), &DeviceConnection::helmetThresholdChanged, this, disconnect(device.get(), &DeviceConnection::detectThresholdChanged, this,
&Application::onDeviceHelmetThreshold); &Application::onDeviceDetectThresholdChanged);
disconnect(device.get(), &DeviceConnection::networkInfomationChanged, this, disconnect(device.get(), &DeviceConnection::networkInfomationChanged, this,
&Application::onDeviceNetworkInfomation); &Application::onDeviceNetworkInfomation);
disconnect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware); 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::openDoorAreaChanged, this, &Application::onDeviceOpenDoorArea);
connect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea); connect(device.get(), &DeviceConnection::shieldedAreaChanged, this, &Application::onDeviceShieldedArea);
connect(device.get(), &DeviceConnection::antiClipAreaChanged, this, &Application::onDeviceAntiClipArea); 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, connect(device.get(), &DeviceConnection::networkInfomationChanged, this,
&Application::onDeviceNetworkInfomation); &Application::onDeviceNetworkInfomation);
connect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware); connect(device.get(), &DeviceConnection::firmwareChanged, this, &Application::onDeviceFirmware);
@ -302,6 +333,8 @@ void Application::connectToDevice(int index) {
m_currentDeviceFlip = info.flip; m_currentDeviceFlip = info.flip;
m_currentDeviceRotation = info.rotation; m_currentDeviceRotation = info.rotation;
m_currentHelmetThreshold = info.helmetThreshold; m_currentHelmetThreshold = info.helmetThreshold;
m_currentHeadThreshold = info.headThreshold;
m_currentDetectFrameSize = info.detectFrameSize;
emit currentDeviceRotationChanged(); emit currentDeviceRotationChanged();
emit currentDeviceFlipChanged(); emit currentDeviceFlipChanged();
emit currentOpenDoorAreaPointsChanged(); emit currentOpenDoorAreaPointsChanged();
@ -312,6 +345,8 @@ void Application::connectToDevice(int index) {
emit currentAntiClipAreaEnabledChanged(); emit currentAntiClipAreaEnabledChanged();
emit currentAntiClipSensitivityChanged(); emit currentAntiClipSensitivityChanged();
emit currentHelmetThresholdChanged(); emit currentHelmetThresholdChanged();
emit currentHeadThresholdChanged();
emit currentDetectFrameSizeChanged();
emit currentNetworkInfomationChanged(); emit currentNetworkInfomationChanged();
} }
emit currentFirmwareChanged(); emit currentFirmwareChanged();
@ -378,8 +413,10 @@ void Application::onDeviceAntiClipArea(bool enabled, const QList<QPointF> &point
setCurrentAntiClipSensitivity(sensitivity); setCurrentAntiClipSensitivity(sensitivity);
} }
void Application::onDeviceHelmetThreshold(int threshold) { void Application::onDeviceDetectThresholdChanged(int helmetThreshold, int headThreshold, int detectFrameSize) {
setCurrentHelmetThreshold(threshold); setCurrentHelmetThreshold(helmetThreshold);
setCurrentHeadThreshold(headThreshold);
setCurrentDetectFrameSize(detectFrameSize);
} }
void Application::onDeviceNetworkInfomation(const NetworkInfomation &info) { void Application::onDeviceNetworkInfomation(const NetworkInfomation &info) {

View File

@ -37,6 +37,10 @@ class Application : public QObject {
Q_PROPERTY(int currentAntiClipSensitivity READ currentAntiClipSensitivity WRITE setCurrentAntiClipSensitivity NOTIFY currentAntiClipSensitivityChanged) Q_PROPERTY(int currentAntiClipSensitivity READ currentAntiClipSensitivity WRITE setCurrentAntiClipSensitivity NOTIFY currentAntiClipSensitivityChanged)
Q_PROPERTY(int currentHelmetThreshold READ currentHelmetThreshold WRITE setCurrentHelmetThreshold NOTIFY Q_PROPERTY(int currentHelmetThreshold READ currentHelmetThreshold WRITE setCurrentHelmetThreshold NOTIFY
currentHelmetThresholdChanged) currentHelmetThresholdChanged)
Q_PROPERTY(int currentHeadThreshold READ currentHeadThreshold WRITE setCurrentHeadThreshold NOTIFY
currentHeadThresholdChanged)
Q_PROPERTY(int currentDetectFrameSize READ currentDetectFrameSize WRITE setCurrentDetectFrameSize NOTIFY
currentDetectFrameSizeChanged)
Q_PROPERTY(QList<QPointF> currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE Q_PROPERTY(QList<QPointF> currentAntiClipAreaPoints READ currentAntiClipAreaPoints WRITE
setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged) setCurrentAntiClipAreaPoints NOTIFY currentAntiClipAreaPointsChanged)
Q_PROPERTY( Q_PROPERTY(
@ -82,6 +86,12 @@ public:
int currentHelmetThreshold() const; int currentHelmetThreshold() const;
void setCurrentHelmetThreshold(int threshold); void setCurrentHelmetThreshold(int threshold);
int currentHeadThreshold() const;
void setCurrentHeadThreshold(int threshold);
int currentDetectFrameSize() const;
void setCurrentDetectFrameSize(int size);
Q_INVOKABLE void updateOpenDoorAreaPoints(const QList<QPointF> &points); Q_INVOKABLE void updateOpenDoorAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateAntiClipAreaPoints(const QList<QPointF> &points); Q_INVOKABLE void updateAntiClipAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateShieldedAreaPoints(const QList<QPointF> &points); Q_INVOKABLE void updateShieldedAreaPoints(const QList<QPointF> &points);
@ -105,6 +115,8 @@ signals:
void currentAntiClipAreaEnabledChanged(); void currentAntiClipAreaEnabledChanged();
void currentAntiClipSensitivityChanged(); void currentAntiClipSensitivityChanged();
void currentHelmetThresholdChanged(); void currentHelmetThresholdChanged();
void currentDetectFrameSizeChanged();
void currentHeadThresholdChanged();
void currentNetworkInfomationChanged(); void currentNetworkInfomationChanged();
void currentFirmwareChanged(); void currentFirmwareChanged();
void currentDeviceConnectedChanged(); void currentDeviceConnectedChanged();
@ -120,7 +132,7 @@ protected:
void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points); void onDeviceOpenDoorArea(DeviceConnection::AreaWay way, const QList<QPointF> &points);
void onDeviceShieldedArea(bool enabled, const QList<QPointF> &points); void onDeviceShieldedArea(bool enabled, const QList<QPointF> &points);
void onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points, int sensitivity); void onDeviceAntiClipArea(bool enabled, const QList<QPointF> &points, int sensitivity);
void onDeviceHelmetThreshold(int threshold); void onDeviceDetectThresholdChanged(int helmetThreshold, int headThreshold, int detectFrameSize);
void onDeviceNetworkInfomation(const NetworkInfomation &info); void onDeviceNetworkInfomation(const NetworkInfomation &info);
void onDeviceFirmware(const QString &firmware); void onDeviceFirmware(const QString &firmware);
void onDeviceConnected(); void onDeviceConnected();
@ -148,6 +160,8 @@ private:
bool m_currentDeviceFlip = false; bool m_currentDeviceFlip = false;
int m_currentDeviceRotation = 0; int m_currentDeviceRotation = 0;
int m_currentHelmetThreshold = 1; int m_currentHelmetThreshold = 1;
int m_currentHeadThreshold = 2;
int m_currentDetectFrameSize = 3;
}; };
#endif // APPLICATION_H #endif // APPLICATION_H

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16) 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(APPLICATION_NAME "视觉防夹设备上位机工具")
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)

View File

@ -240,16 +240,24 @@ void DeviceConnection::updateAntiClipAreaPoints(bool enabled, const QList<QPoint
m_requests.push(task); m_requests.push(task);
} }
QFuture<bool> DeviceConnection::updateHelmetThreshold(int threshold) { QFuture<bool> DeviceConnection::updateDetectThreshold(int helmetThreshold, int headThreshold, int detectFrameSize) {
constexpr auto command = "thresholdwithhat_setdata"; constexpr auto command = "headdetectparam_setdata";
Task task; Task task;
task.command = command; task.command = command;
task.task = [this, threshold, command]() { task.task = [this, helmetThreshold, headThreshold, detectFrameSize, command]() {
boost::json::object request; boost::json::object request;
request["func"] = command; request["func"] = command;
request["deviceid"] = "0"; request["deviceid"] = "0";
boost::json::object data; 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); request["data"] = std::move(data);
auto text = boost::json::serialize(request); auto text = boost::json::serialize(request);
m_commandSocket->write(text.data(), text.size()); m_commandSocket->write(text.data(), text.size());
@ -263,8 +271,8 @@ QFuture<bool> DeviceConnection::updateHelmetThreshold(int threshold) {
return ret; return ret;
} }
void DeviceConnection::requestHelmetThreshold() { void DeviceConnection::requestHeadDetectThreshold() {
constexpr auto command = "thresholdwithhat_getdata"; constexpr auto command = "headdetectparam_getdata";
Task task; Task task;
task.command = command; task.command = command;
task.task = [this, command]() { task.task = [this, command]() {
@ -739,11 +747,13 @@ QString DeviceConnection::handleCommand(const std::string_view &replyText, const
requestVideoInformation(); requestVideoInformation();
} else if (function == "a12factory_setdata") { } else if (function == "a12factory_setdata") {
LOG(info) << "device factory reset"; LOG(info) << "device factory reset";
} else if (function == "thresholdwithhat_getdata") { } else if (function == "headdetectparam_getdata") {
auto &data = reply.at("data").as_object(); auto &data = reply.at("data").as_object();
auto &value = data.at("value").as_int64(); m_infomation.helmetThreshold = data.at("hatthreshold").as_int64();
m_infomation.helmetThreshold = value; m_infomation.headThreshold = data.at("headthreshold").as_int64();
emit helmetThresholdChanged(m_infomation.helmetThreshold); m_infomation.detectFrameSize = data.at("detectframenum").as_int64();
emit detectThresholdChanged(m_infomation.helmetThreshold, m_infomation.headThreshold,
m_infomation.detectFrameSize);
} else if (function == "thresholdwithhat_setdata") { } else if (function == "thresholdwithhat_setdata") {
if ((task != nullptr) && (task->command.toStdString() == function)) { if ((task != nullptr) && (task->command.toStdString() == function)) {
if (task->timeoutTimer) { if (task->timeoutTimer) {
@ -769,7 +779,7 @@ void DeviceConnection::onConnected() {
requestAntiClipArea(); requestAntiClipArea();
requestNetworkInfomation(); requestNetworkInfomation();
requestVideoInformation(); requestVideoInformation();
requestHelmetThreshold(); requestHeadDetectThreshold();
emit connected(); emit connected();
m_heartbeatTimerId = startTimer(2500); m_heartbeatTimerId = startTimer(2500);
if (m_otaProgress == 99) { if (m_otaProgress == 99) {

View File

@ -49,6 +49,8 @@ public:
bool antiClipAreaEnabled; bool antiClipAreaEnabled;
int antiClipSensitivity = 1; int antiClipSensitivity = 1;
int helmetThreshold = 1; int helmetThreshold = 1;
int headThreshold = 1;
int detectFrameSize = 1;
}; };
Q_ENUM(AreaWay) Q_ENUM(AreaWay)
@ -72,8 +74,8 @@ public:
void updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points, int sensitivity); void updateAntiClipAreaPoints(bool enabled, const QList<QPointF> &points, int sensitivity);
void requestResolution(Resolution resolution); void requestResolution(Resolution resolution);
void requestNetworkInfomation(); void requestNetworkInfomation();
QFuture<bool> updateHelmetThreshold(int threshold); QFuture<bool> updateDetectThreshold(int helmetThreshold, int headThreshold, int detectFrameSize);
void requestHelmetThreshold(); void requestHeadDetectThreshold();
QFuture<bool> updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway, QFuture<bool> updateNetworkInfomation(bool dhcp, const QString &ip, const QString &netmask, const QString &gateway,
const QString &dns); const QString &dns);
void requestVersion(); void requestVersion();
@ -101,7 +103,7 @@ signals:
void antiClipAreaChanged(bool enabled, const QList<QPointF> &points, int sensitivity); void antiClipAreaChanged(bool enabled, const QList<QPointF> &points, int sensitivity);
void rotationChanged(int rotation); void rotationChanged(int rotation);
void flipChanged(bool flip); void flipChanged(bool flip);
void helmetThresholdChanged(int threshold); void detectThresholdChanged(int helmetThreshold, int headThreshold, int detectFrameSize);
void networkInfomationChanged(const NetworkInfomation &info); void networkInfomationChanged(const NetworkInfomation &info);
void firmwareChanged(const QString &firmware); void firmwareChanged(const QString &firmware);
void otaProgressChanged(bool status, int progress, const QString &message); void otaProgressChanged(bool status, int progress, const QString &message);

View File

@ -18,6 +18,8 @@ Item {
property bool antiClipAreaEnabled: false property bool antiClipAreaEnabled: false
property int antiClipSensitivity: 1 property int antiClipSensitivity: 1
property alias helmetThreshold: helmetInput.text property alias helmetThreshold: helmetInput.text
property alias headThreshold: headInput.text
property alias detectFrameSize: detectFrameInput.text
property alias flip: flipSwitch.checked property alias flip: flipSwitch.checked
property alias videoRotation: rotateComboBox.currentIndex property alias videoRotation: rotateComboBox.currentIndex
@ -248,13 +250,12 @@ Item {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
columns: 6 columns: 2
Label { text: qsTr("图像: ") } Label { text: qsTr("图像: ") }
Row { Row {
enabled: root.enabled enabled: root.enabled
Layout.columnSpan: 5
Label { Label {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: qsTr("旋转") text: qsTr("旋转")
@ -282,9 +283,9 @@ Item {
Label { Label {
text: qsTr("开门区域: ") text: qsTr("开门区域: ")
} }
Row { Row {
enabled: root.enabled enabled: root.enabled
Layout.columnSpan: 5
RadioButton { RadioButton {
text: "关闭" text: "关闭"
checked: App.currentOpenDoorAreaWay ==DeviceConnection.Diabled checked: App.currentOpenDoorAreaWay ==DeviceConnection.Diabled
@ -308,11 +309,17 @@ Item {
} }
} }
Label {
Layout.alignment: Qt.AlignTop
Layout.topMargin: 14
text: qsTr("防夹区域: ")
}
Label {text: qsTr("防夹区域: ")} Flow{
Row { Layout.fillHeight: true
Layout.fillWidth: true
RowLayout {
enabled: root.enabled enabled: root.enabled
Layout.columnSpan: 1
RadioButton { RadioButton {
text: "关闭" text: "关闭"
checked: !App.currentAntiClipAreaEnabled checked: !App.currentAntiClipAreaEnabled
@ -327,9 +334,11 @@ Item {
onToggled: { onToggled: {
App.currentAntiClipAreaEnabled=true App.currentAntiClipAreaEnabled=true
} }
Layout.rightMargin: 20
} }
} }
RowLayout {
Label { text: qsTr("灵敏度: ") Label { text: qsTr("灵敏度: ")
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
} }
@ -343,8 +352,10 @@ Item {
onCurrentIndexChanged: { onCurrentIndexChanged: {
App.currentAntiClipSensitivity = antiClipSensitivityComboBox.currentIndex+1 App.currentAntiClipSensitivity = antiClipSensitivityComboBox.currentIndex+1
} }
Layout.rightMargin: 20
} }
}
RowLayout {
Label { text: qsTr("安全帽阈值: ") Label { text: qsTr("安全帽阈值: ")
Layout.alignment: Qt.AlignRight Layout.alignment: Qt.AlignRight
} }
@ -353,6 +364,9 @@ Item {
enabled: root.enabled enabled: root.enabled
implicitWidth: 60 implicitWidth: 60
Layout.alignment: Qt.AlignLeft Layout.alignment: Qt.AlignLeft
selectByMouse: true
ToolTip.visible: helmetInput.hovered
ToolTip.text: "阈值范围 0-300"
validator: IntValidator { validator: IntValidator {
bottom: 0 bottom: 0
top: 300 top: 300
@ -363,7 +377,62 @@ Item {
window.showSuccess("设置成功",2500) window.showSuccess("设置成功",2500)
} }
} }
Layout.rightMargin: 20
} }
}
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
}
}
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("屏蔽区域: ")} Label {text: qsTr("屏蔽区域: ")}
Row { Row {

View File

@ -122,6 +122,8 @@ ApplicationWindow {
antiClipSensitivity: App.currentAntiClipSensitivity antiClipSensitivity: App.currentAntiClipSensitivity
antiClipAreaPoints: App.currentAntiClipAreaPoints antiClipAreaPoints: App.currentAntiClipAreaPoints
helmetThreshold: App.currentHelmetThreshold helmetThreshold: App.currentHelmetThreshold
headThreshold: App.currentHeadThreshold
detectFrameSize: App.currentDetectFrameSize
flip: App.currentDeviceFlip flip: App.currentDeviceFlip
videoRotation: App.currentDeviceRotation videoRotation: App.currentDeviceRotation
} }