初始化
This commit is contained in:
312
rg-09112127/html/test_hand_detection.html
Normal file
312
rg-09112127/html/test_hand_detection.html
Normal file
@@ -0,0 +1,312 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>举手检测测试</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
background: white;
|
||||
padding: 30px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.test-section {
|
||||
margin: 20px 0;
|
||||
padding: 20px;
|
||||
border: 2px solid #4ecdc4;
|
||||
border-radius: 10px;
|
||||
}
|
||||
.status {
|
||||
margin: 10px 0;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.success {
|
||||
background: #d4edda;
|
||||
color: #155724;
|
||||
}
|
||||
.error {
|
||||
background: #f8d7da;
|
||||
color: #721c24;
|
||||
}
|
||||
.info {
|
||||
background: #d1ecf1;
|
||||
color: #0c5460;
|
||||
}
|
||||
button {
|
||||
background: #4ecdc4;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
margin: 5px;
|
||||
}
|
||||
button:hover {
|
||||
background: #45b7aa;
|
||||
}
|
||||
.test-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
.test-btn {
|
||||
background: #28a745;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 15px 25px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
.test-btn:hover {
|
||||
background: #218838;
|
||||
}
|
||||
/* 体感交互容器样式 */
|
||||
.box-body {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
border-radius: 15px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
|
||||
z-index: 2000;
|
||||
max-width: 500px;
|
||||
text-align: center;
|
||||
}
|
||||
.box-body img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
border-radius: 10px;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.box-body div {
|
||||
margin: 10px 0;
|
||||
padding: 5px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>🖐️ 举手检测测试</h1>
|
||||
|
||||
<div class="test-section">
|
||||
<h3>📋 测试说明</h3>
|
||||
<p>这个页面用于测试体感交互系统是否能正确检测举手动作。</p>
|
||||
<ul>
|
||||
<li>点击"启动体感交互"按钮</li>
|
||||
<li>允许摄像头权限</li>
|
||||
<li>举起左手或右手</li>
|
||||
<li>观察是否能正确检测并点击对应按钮</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h3>🎮 测试按钮</h3>
|
||||
<p>这些按钮用于测试体感交互是否能正确点击:</p>
|
||||
<div class="test-buttons">
|
||||
<button class="test-btn" id="leftBtn" onclick="testLeftClick()">
|
||||
左手按钮
|
||||
</button>
|
||||
<button class="test-btn" id="rightBtn" onclick="testRightClick()">
|
||||
右手按钮
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h3>📊 检测状态</h3>
|
||||
<div id="connectionStatus" class="status info">
|
||||
未连接到体感检测服务器
|
||||
</div>
|
||||
<div id="handStatus" class="status info">等待检测...</div>
|
||||
<div id="clickStatus" class="status info">等待按钮点击...</div>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h3>🔧 控制面板</h3>
|
||||
<button onclick="startBodySensation()">启动体感交互</button>
|
||||
<button onclick="stopBodySensation()">停止体感交互</button>
|
||||
<button onclick="checkElements()">检查页面元素</button>
|
||||
<button onclick="clearLogs()">清除日志</button>
|
||||
</div>
|
||||
|
||||
<div class="test-section">
|
||||
<h3>📝 调试日志</h3>
|
||||
<div
|
||||
id="debugLog"
|
||||
style="
|
||||
background: #f8f9fa;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
"
|
||||
>
|
||||
等待日志输出...
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 体感交互容器(用于directBodySensation.js) -->
|
||||
<div class="box-body" style="display: none">
|
||||
<div id="bodyConnectionStatus">未连接到服务器</div>
|
||||
<img id="bodyVideoFeed" src="" alt="体感检测视频" />
|
||||
<div id="bodyHandStatus">等待检测...</div>
|
||||
</div>
|
||||
|
||||
<!-- 引入体感交互脚本 -->
|
||||
<script src="../js/directBodySensation.js"></script>
|
||||
|
||||
<script>
|
||||
let clickCount = { left: 0, right: 0 };
|
||||
|
||||
// 测试左手按钮点击
|
||||
function testLeftClick() {
|
||||
clickCount.left++;
|
||||
updateClickStatus();
|
||||
log(`左手按钮被点击 (第${clickCount.left}次)`);
|
||||
}
|
||||
|
||||
// 测试右手按钮点击
|
||||
function testRightClick() {
|
||||
clickCount.right++;
|
||||
updateClickStatus();
|
||||
log(`右手按钮被点击 (第${clickCount.right}次)`);
|
||||
}
|
||||
|
||||
// 更新点击状态
|
||||
function updateClickStatus() {
|
||||
const statusDiv = document.getElementById("clickStatus");
|
||||
statusDiv.textContent = `左手点击: ${clickCount.left}次, 右手点击: ${clickCount.right}次`;
|
||||
statusDiv.className = "status success";
|
||||
}
|
||||
|
||||
// 启动体感交互
|
||||
function startBodySensation() {
|
||||
log("正在启动体感交互系统...");
|
||||
|
||||
try {
|
||||
if (typeof showBody === "function") {
|
||||
showBody();
|
||||
log("✅ 体感交互系统已启动");
|
||||
} else {
|
||||
log("❌ 体感交互系统未加载");
|
||||
}
|
||||
} catch (error) {
|
||||
log(`❌ 启动体感交互错误: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 停止体感交互
|
||||
function stopBodySensation() {
|
||||
log("正在停止体感交互系统...");
|
||||
|
||||
try {
|
||||
if (typeof showBody === "function") {
|
||||
showBody(); // 再次调用会切换状态
|
||||
log("✅ 体感交互系统已停止");
|
||||
} else {
|
||||
log("❌ 体感交互系统未加载");
|
||||
}
|
||||
} catch (error) {
|
||||
log(`❌ 停止体感交互错误: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 检查页面元素
|
||||
function checkElements() {
|
||||
log("检查页面元素...");
|
||||
|
||||
const elements = {
|
||||
"box-body": document.querySelector(".box-body"),
|
||||
bodyConnectionStatus: document.getElementById("bodyConnectionStatus"),
|
||||
bodyVideoFeed: document.getElementById("bodyVideoFeed"),
|
||||
bodyHandStatus: document.getElementById("bodyHandStatus"),
|
||||
leftBtn: document.getElementById("leftBtn"),
|
||||
rightBtn: document.getElementById("rightBtn"),
|
||||
};
|
||||
|
||||
for (const [name, element] of Object.entries(elements)) {
|
||||
if (element) {
|
||||
log(`✅ ${name}: 存在`);
|
||||
} else {
|
||||
log(`❌ ${name}: 不存在`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 清除日志
|
||||
function clearLogs() {
|
||||
document.getElementById("debugLog").textContent = "日志已清除...";
|
||||
clickCount = { left: 0, right: 0 };
|
||||
updateClickStatus();
|
||||
}
|
||||
|
||||
// 日志函数
|
||||
function log(message) {
|
||||
const logDiv = document.getElementById("debugLog");
|
||||
const timestamp = new Date().toLocaleTimeString();
|
||||
logDiv.textContent += `[${timestamp}] ${message}\n`;
|
||||
logDiv.scrollTop = logDiv.scrollHeight;
|
||||
console.log(message);
|
||||
}
|
||||
|
||||
// 监听体感交互状态变化
|
||||
function updateStatus() {
|
||||
const connectionStatus = document.getElementById(
|
||||
"bodyConnectionStatus"
|
||||
);
|
||||
const handStatus = document.getElementById("bodyHandStatus");
|
||||
|
||||
if (connectionStatus) {
|
||||
document.getElementById("connectionStatus").textContent =
|
||||
connectionStatus.textContent;
|
||||
}
|
||||
|
||||
if (handStatus) {
|
||||
document.getElementById("handStatus").textContent =
|
||||
handStatus.textContent;
|
||||
}
|
||||
}
|
||||
|
||||
// 页面加载完成后自动初始化
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
log("🖐️ 举手检测测试页面已加载");
|
||||
|
||||
// 定期更新状态
|
||||
setInterval(updateStatus, 1000);
|
||||
|
||||
log("✅ 页面初始化完成,可以开始测试");
|
||||
});
|
||||
|
||||
// 重写 console.log 来捕获体感交互的日志
|
||||
const originalLog = console.log;
|
||||
console.log = function (...args) {
|
||||
originalLog.apply(console, args);
|
||||
if (args[0] && typeof args[0] === "string") {
|
||||
if (
|
||||
args[0].includes("clickBth") ||
|
||||
args[0].includes("找到的按钮") ||
|
||||
args[0].includes("点击了")
|
||||
) {
|
||||
log(args.join(" "));
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user