From c7f96636f35f8e5fa3c45bdae54de6a3f3317353 Mon Sep 17 00:00:00 2001 From: root <13910913995@163.com> Date: Wed, 6 Aug 2025 14:24:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E5=A4=B4=E9=83=A8?= =?UTF-8?q?=E5=A7=BF=E6=80=81=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/renderer/src/views/Detection.vue | 218 +++++++++++++++++- 1 file changed, 207 insertions(+), 11 deletions(-) diff --git a/frontend/src/renderer/src/views/Detection.vue b/frontend/src/renderer/src/views/Detection.vue index 41f0b015..47b4a805 100644 --- a/frontend/src/renderer/src/views/Detection.vue +++ b/frontend/src/renderer/src/views/Detection.vue @@ -78,10 +78,26 @@ 头部姿态 - - 清零 - +
+ + {{ isTrackingMaxValues ? '跟踪中' : '清零' }} + + + 保存 + +
@@ -91,25 +107,28 @@
-
左:-55.2°
+
旋转
+
左:{{ headPoseMaxValues.rotationLeftMax.toFixed(1) }}°
右:-55.2°
+ class="gauge-group-box-text2">{{ headPoseMaxValues.rotationRightMax.toFixed(1) }}°
-
左:-7.7°
+
倾斜
+
左:{{ headPoseMaxValues.tiltLeftMax.toFixed(1) }}°
右:8.7°
+ class="gauge-group-box-text2">{{ headPoseMaxValues.tiltRightMax.toFixed(1) }}°
-
左:-10.5°
-
右:11.5°
+
俯仰
+
下:{{ headPoseMaxValues.pitchDownMax.toFixed(1) }}°
+
上:{{ headPoseMaxValues.pitchUpMax.toFixed(1) }}°
@@ -642,6 +661,22 @@ function displayDepthCameraFrame(base64Image) { } +// 头部姿态最值跟踪数据 +const headPoseMaxValues = ref({ + rotationLeftMax: 0, // 旋转-左旋最大值 + rotationRightMax: 0, // 旋转-右旋最大值 + tiltLeftMax: 0, // 倾斜-左倾最大值 + tiltRightMax: 0, // 倾斜-右倾最大值 + pitchUpMax: 0, // 俯仰-上仰最大值 + pitchDownMax: 0 // 俯仰-下俯最大值 +}) + +// 头部姿态历史最值记录数组 +const headPoseHistory = ref([]) + +// 最值跟踪状态 +const isTrackingMaxValues = ref(false) + // 处理IMU头部姿态数据 function handleIMUData(data) { try { @@ -658,6 +693,11 @@ function handleIMUData(data) { // 显示角度值(保留一位小数) console.log(`📐 头部姿态角度 - 旋转: ${headPose.rotation.toFixed(1)}°, 倾斜: ${headPose.tilt.toFixed(1)}°, 俯仰: ${headPose.pitch.toFixed(1)}°`) + // 如果正在跟踪最值,则更新最值数据 + if (isTrackingMaxValues.value) { + updateHeadPoseMaxValues(headPose) + } + // 这里可以添加数据可视化逻辑 // 例如更新图表或显示数值 @@ -673,6 +713,162 @@ function handleIMUData(data) { } } +// 更新头部姿态最值 +function updateHeadPoseMaxValues(headPose) { + try { + // 更新旋转角最值 + if (headPose.rotation < 0) { + // 左旋(负值),取绝对值的最大值 + headPoseMaxValues.value.rotationLeftMax = Math.min( + headPoseMaxValues.value.rotationLeftMax, + Math.abs(headPose.rotation) + ) + } else if (headPose.rotation > 0) { + // 右旋(正值) + headPoseMaxValues.value.rotationRightMax = Math.max( + headPoseMaxValues.value.rotationRightMax, + headPose.rotation + ) + } + + // 更新倾斜角最值 + if (headPose.tilt < 0) { + // 左倾(负值),取绝对值的最大值 + headPoseMaxValues.value.tiltLeftMax = Math.min( + headPoseMaxValues.value.tiltLeftMax, + Math.abs(headPose.tilt) + ) + } else if (headPose.tilt > 0) { + // 右倾(正值) + headPoseMaxValues.value.tiltRightMax = Math.max( + headPoseMaxValues.value.tiltRightMax, + headPose.tilt + ) + } + + // 更新俯仰角最值 + if (headPose.pitch < 0) { + // 下俯(负值),取绝对值的最大值 + headPoseMaxValues.value.pitchDownMax = Math.min( + headPoseMaxValues.value.pitchDownMax, + Math.abs(headPose.pitch) + ) + } else if (headPose.pitch > 0) { + // 上仰(正值) + headPoseMaxValues.value.pitchUpMax = Math.max( + headPoseMaxValues.value.pitchUpMax, + headPose.pitch + ) + } + + // 输出当前最值(用于调试) + console.log('📊 当前头部姿态最值:', { + rotationLeft: headPoseMaxValues.value.rotationLeftMax.toFixed(1), + rotationRight: headPoseMaxValues.value.rotationRightMax.toFixed(1), + tiltLeft: headPoseMaxValues.value.tiltLeftMax.toFixed(1), + tiltRight: headPoseMaxValues.value.tiltRightMax.toFixed(1), + pitchUp: headPoseMaxValues.value.pitchUpMax.toFixed(1), + pitchDown: headPoseMaxValues.value.pitchDownMax.toFixed(1) + }) + } catch (error) { + console.error('❌ 更新头部姿态最值失败:', error) + } +} + +// 清零最值并开始跟踪 +function clearAndStartTracking() { + try { + saveMaxValuesToHistory() + + // 重置所有最值为0 + headPoseMaxValues.value = { + rotationLeftMax: 0, + rotationRightMax: 0, + tiltLeftMax: 0, + tiltRightMax: 0, + pitchUpMax: 0, + pitchDownMax: 0 + } + + // 开始跟踪 + isTrackingMaxValues.value = true + + console.log('🔄 头部姿态最值已清零,开始跟踪') + ElMessage.success('头部姿态最值已清零,开始跟踪') + } catch (error) { + console.error('❌ 清零最值失败:', error) + ElMessage.error('清零最值失败') + } +} + +// 保存当前最值到历史记录 +function saveMaxValuesToHistory() { + try { + if (!isTrackingMaxValues.value) { + ElMessage.warning('请先点击清零开始跟踪') + return + } + + // 创建当前最值的副本 + const currentMaxValues = { + id: headPoseHistory.value.length + 1, + rotationLeftMax: Number(headPoseMaxValues.value.rotationLeftMax.toFixed(1)), + rotationRightMax: Number(headPoseMaxValues.value.rotationRightMax.toFixed(1)), + tiltLeftMax: Number(headPoseMaxValues.value.tiltLeftMax.toFixed(1)), + tiltRightMax: Number(headPoseMaxValues.value.tiltRightMax.toFixed(1)), + pitchUpMax: Number(headPoseMaxValues.value.pitchUpMax.toFixed(1)), + pitchDownMax: Number(headPoseMaxValues.value.pitchDownMax.toFixed(1)), + timestamp: new Date().toLocaleString() + } + + // 添加到历史记录 + headPoseHistory.value.push(currentMaxValues) + + // 停止跟踪 + isTrackingMaxValues.value = false + + console.log('💾 头部姿态最值已保存:', currentMaxValues) + ElMessage.success(`头部姿态最值已保存(第${currentMaxValues.id}组)`) + + // 更新历史数据表格(如果存在的话) + updateHistoryTable() + } catch (error) { + console.error('❌ 保存最值失败:', error) + ElMessage.error('保存最值失败') + } +} + +// 更新历史数据表格 +function updateHistoryTable() { + try { + // 将头部姿态最值数据合并到现有的历史数据中 + if (headPoseHistory.value.length > 0) { + const latestData = headPoseHistory.value[headPoseHistory.value.length - 1] + + // 更新historyData数组,添加头部姿态最值数据 + const newHistoryItem = { + id: latestData.id, + rotLeft: latestData.rotationLeftMax, + rotRight: latestData.rotationRightMax, + tiltLeft: latestData.tiltLeftMax, + tiltRight: latestData.tiltRightMax, + pitchDown: latestData.pitchDownMax, + pitchUp: latestData.pitchUpMax, + timestamp: latestData.timestamp + } + + // 如果historyData数组存在,则添加新数据 + if (historyData.value) { + historyData.value.push(newHistoryItem) + } + + console.log('📋 历史数据表格已更新') + } + } catch (error) { + console.error('❌ 更新历史数据表格失败:', error) + } +} + // 处理压力传感器足部压力数据 function handlePressureData(data) { try {