实现检测阈值设置。

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();
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<QPointF> &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) {

View File

@ -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<QPointF> 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<QPointF> &points);
Q_INVOKABLE void updateAntiClipAreaPoints(const QList<QPointF> &points);
Q_INVOKABLE void updateShieldedAreaPoints(const QList<QPointF> &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<QPointF> &points);
void onDeviceShieldedArea(bool enabled, const QList<QPointF> &points);
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 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

View File

@ -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)

View File

@ -240,16 +240,24 @@ void DeviceConnection::updateAntiClipAreaPoints(bool enabled, const QList<QPoint
m_requests.push(task);
}
QFuture<bool> DeviceConnection::updateHelmetThreshold(int threshold) {
constexpr auto command = "thresholdwithhat_setdata";
QFuture<bool> 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<bool> 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) {

View File

@ -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<QPointF> &points, int sensitivity);
void requestResolution(Resolution resolution);
void requestNetworkInfomation();
QFuture<bool> updateHelmetThreshold(int threshold);
void requestHelmetThreshold();
QFuture<bool> updateDetectThreshold(int helmetThreshold, int headThreshold, int detectFrameSize);
void requestHeadDetectThreshold();
QFuture<bool> 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<QPointF> &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);

View File

@ -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,11 +309,17 @@ Item {
}
}
Label {
Layout.alignment: Qt.AlignTop
Layout.topMargin: 14
text: qsTr("防夹区域: ")
}
Label {text: qsTr("防夹区域: ")}
Row {
Flow{
Layout.fillHeight: true
Layout.fillWidth: true
RowLayout {
enabled: root.enabled
Layout.columnSpan: 1
RadioButton {
text: "关闭"
checked: !App.currentAntiClipAreaEnabled
@ -327,9 +334,11 @@ Item {
onToggled: {
App.currentAntiClipAreaEnabled=true
}
Layout.rightMargin: 20
}
}
RowLayout {
Label { text: qsTr("灵敏度: ")
Layout.alignment: Qt.AlignRight
}
@ -343,8 +352,10 @@ Item {
onCurrentIndexChanged: {
App.currentAntiClipSensitivity = antiClipSensitivityComboBox.currentIndex+1
}
Layout.rightMargin: 20
}
}
RowLayout {
Label { text: qsTr("安全帽阈值: ")
Layout.alignment: Qt.AlignRight
}
@ -353,6 +364,9 @@ Item {
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
@ -363,7 +377,62 @@ Item {
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("屏蔽区域: ")}
Row {

View File

@ -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
}