af6c04ccb1
- 单文件后端(标准库HTTP) + 单文件前端,依赖仅 pyrealsense2/numpy/opencv-headless - 可调分辨率/帧率/曝光/增益,定时录制,自定义保存位置 - 输出 color.mp4 + 对齐深度16bit PNG + intrinsics.json(内参/时间戳) - 拉帧自愈预览与流级自动重启,README 含操作说明与 API Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
267 lines
9.5 KiB
HTML
267 lines
9.5 KiB
HTML
<!doctype html>
|
||
<html lang="zh">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>D405 采集台</title>
|
||
<style>
|
||
:root{
|
||
--bg:#101418; --panel:#1a2027; --line:#2a323c; --txt:#dde3ea; --dim:#8a95a3;
|
||
--acc:#3d9df0; --rec:#e0453a;
|
||
}
|
||
*{box-sizing:border-box}
|
||
body{margin:0;background:var(--bg);color:var(--txt);
|
||
font:14px/1.5 system-ui,"Noto Sans CJK SC",sans-serif}
|
||
header{display:flex;align-items:center;gap:14px;padding:10px 18px;
|
||
border-bottom:1px solid var(--line)}
|
||
header h1{font-size:16px;margin:0;font-weight:600}
|
||
#conn{font-size:12px;color:var(--dim)}
|
||
#conn.bad{color:var(--rec)}
|
||
main{display:flex;gap:14px;padding:14px;align-items:flex-start;flex-wrap:wrap}
|
||
#viewwrap{flex:1 1 640px;min-width:320px}
|
||
#view{width:100%;display:block;background:#000;border:1px solid var(--line);
|
||
border-radius:8px;min-height:200px}
|
||
#overlay{display:flex;gap:16px;margin-top:6px;font-size:13px;color:var(--dim)}
|
||
aside{width:300px;flex:0 0 300px;display:flex;flex-direction:column;gap:12px}
|
||
.card{background:var(--panel);border:1px solid var(--line);border-radius:10px;
|
||
padding:12px 14px}
|
||
.card h2{margin:0 0 10px;font-size:13px;color:var(--dim);font-weight:600;
|
||
text-transform:none;letter-spacing:.5px}
|
||
.row{display:flex;align-items:center;justify-content:space-between;
|
||
gap:10px;margin:8px 0}
|
||
.row label{color:var(--txt)}
|
||
select,input[type=number]{background:#12171d;color:var(--txt);
|
||
border:1px solid var(--line);border-radius:6px;padding:5px 8px;width:130px}
|
||
input[type=range]{width:130px;accent-color:var(--acc)}
|
||
input[type=checkbox]{width:16px;height:16px;accent-color:var(--acc)}
|
||
.val{color:var(--dim);font-size:12px;min-width:38px;text-align:right}
|
||
button{border:0;border-radius:8px;padding:10px 0;width:100%;font-size:16px;
|
||
font-weight:600;cursor:pointer;transition:background .15s}
|
||
#recbtn{background:var(--acc);color:#fff}
|
||
#recbtn.rec{background:var(--rec)}
|
||
#recbtn:disabled{background:#333;color:#777;cursor:not-allowed}
|
||
#applybtn{background:#2a323c;color:var(--txt);font-size:14px;padding:8px 0}
|
||
#applybtn.dirty{background:#c98a1b;color:#fff}
|
||
#recinfo{margin-top:8px;font-size:13px;color:var(--dim);min-height:20px}
|
||
#recinfo b{color:var(--txt)}
|
||
#saved{font-size:12px;color:var(--dim);margin-top:4px;word-break:break-all}
|
||
#msg{font-size:12px;color:var(--rec);min-height:16px;margin-top:6px}
|
||
.hint{font-size:11px;color:var(--dim);margin-top:2px}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<header>
|
||
<h1>📷 D405 采集台</h1>
|
||
<span id="conn">连接中…</span>
|
||
</header>
|
||
<main>
|
||
<div id="viewwrap">
|
||
<img id="view" alt="live">
|
||
<div id="overlay">
|
||
<span id="ov_mode">—</span><span id="ov_fps">—</span><span id="ov_depth">—</span>
|
||
</div>
|
||
</div>
|
||
<aside>
|
||
<div class="card">
|
||
<h2>录制</h2>
|
||
<button id="recbtn" onclick="toggleRec()">● 开始录制</button>
|
||
<div class="row">
|
||
<label>录制时长(秒)</label>
|
||
<input type="number" id="duration" min="0" max="86400" step="1" value="0"
|
||
style="width:80px">
|
||
</div>
|
||
<div class="hint">0 = 手动停止;填 N 秒到时自动停止保存</div>
|
||
<div class="row">
|
||
<label>保存位置</label>
|
||
<input type="text" id="out_dir" style="width:170px"
|
||
placeholder="默认 hardware/captures">
|
||
</div>
|
||
<div class="hint">目录不存在会自动创建,~ 可用;每段录制在其下建时间戳子目录</div>
|
||
<div class="row">
|
||
<label>保存深度</label>
|
||
<input type="checkbox" id="save_depth" checked>
|
||
</div>
|
||
<div id="recinfo"></div>
|
||
<div id="saved"></div>
|
||
</div>
|
||
<div class="card">
|
||
<h2>视频流(改动需应用,会重启流)</h2>
|
||
<div class="row">
|
||
<label>分辨率</label>
|
||
<select id="res">
|
||
<option value="1280x720">1280×720</option>
|
||
<option value="848x480" selected>848×480</option>
|
||
<option value="640x360">640×360</option>
|
||
<option value="424x240">424×240</option>
|
||
</select>
|
||
</div>
|
||
<div class="row">
|
||
<label>帧率</label>
|
||
<select id="fps">
|
||
<option>5</option><option>15</option><option selected>30</option>
|
||
<option>60</option><option>90</option>
|
||
</select>
|
||
</div>
|
||
<div class="hint">1280×720 最高 30fps;60/90fps 需 848×480 及以下</div>
|
||
<button id="applybtn" onclick="applyStream()">应用视频流设置</button>
|
||
</div>
|
||
<div class="card">
|
||
<h2>预览与深度显示(即时生效)</h2>
|
||
<div class="row">
|
||
<label>预览画质</label>
|
||
<input type="range" id="quality" min="30" max="95" step="5" value="80">
|
||
<span class="val" id="quality_v">80</span>
|
||
</div>
|
||
<div class="row">
|
||
<label>深度范围</label>
|
||
<select id="depth_max">
|
||
<option value="0.5">0 ~ 0.5 m</option>
|
||
<option value="1" selected>0 ~ 1 m</option>
|
||
<option value="2">0 ~ 2 m</option>
|
||
<option value="4">0 ~ 4 m</option>
|
||
</select>
|
||
</div>
|
||
<div class="row">
|
||
<label>预览布局</label>
|
||
<select id="layout">
|
||
<option value="side" selected>彩色 | 深度</option>
|
||
<option value="color">仅彩色</option>
|
||
<option value="depth">仅深度</option>
|
||
</select>
|
||
</div>
|
||
</div>
|
||
<div class="card">
|
||
<h2>传感器(即时生效)</h2>
|
||
<div class="row">
|
||
<label>自动曝光</label>
|
||
<input type="checkbox" id="auto_exp" checked>
|
||
</div>
|
||
<div class="row">
|
||
<label>手动曝光 µs</label>
|
||
<input type="range" id="exposure" min="100" max="30000" step="100" value="8000" disabled>
|
||
<span class="val" id="exposure_v">8000</span>
|
||
</div>
|
||
<div class="row">
|
||
<label>增益</label>
|
||
<input type="range" id="gain" min="16" max="248" step="8" value="64" disabled>
|
||
<span class="val" id="gain_v">64</span>
|
||
</div>
|
||
</div>
|
||
<div id="msg"></div>
|
||
</aside>
|
||
</main>
|
||
<script>
|
||
const $ = id => document.getElementById(id);
|
||
let st = {on:false}, streamDirty = false;
|
||
|
||
// ---- 自愈式拉帧预览:/frame.jpg 服务端等新帧才返回,断了自动重连 ----
|
||
const sleep = ms => new Promise(r=>setTimeout(r,ms));
|
||
let lastUrl = null;
|
||
(async function frameLoop(){
|
||
for(;;){
|
||
try{
|
||
const r = await fetch('/frame.jpg', {cache:'no-store'});
|
||
if(!r.ok) throw 0;
|
||
const url = URL.createObjectURL(await r.blob());
|
||
$('view').src = url;
|
||
if(lastUrl) URL.revokeObjectURL(lastUrl);
|
||
lastUrl = url;
|
||
}catch(e){
|
||
await sleep(700); // 服务端重启视频流期间在此重试
|
||
}
|
||
}
|
||
})();
|
||
|
||
async function api(path, body){
|
||
const r = await fetch(path, body===undefined ? {} :
|
||
{method:'POST', headers:{'Content-Type':'application/json'},
|
||
body:JSON.stringify(body)});
|
||
return r.json();
|
||
}
|
||
|
||
// ---- 即时生效项 ----
|
||
function pushLive(){
|
||
api('/api/config', {
|
||
jpeg_quality:+$('quality').value,
|
||
depth_max:+$('depth_max').value,
|
||
layout:$('layout').value,
|
||
auto_exposure:$('auto_exp').checked,
|
||
exposure:+$('exposure').value,
|
||
gain:+$('gain').value,
|
||
}).catch(()=>{});
|
||
}
|
||
['depth_max','layout'].forEach(id=>$(id).onchange=pushLive);
|
||
$('quality').oninput=()=>{$('quality_v').textContent=$('quality').value};
|
||
$('quality').onchange=pushLive;
|
||
$('exposure').oninput=()=>{$('exposure_v').textContent=$('exposure').value};
|
||
$('exposure').onchange=pushLive;
|
||
$('gain').oninput=()=>{$('gain_v').textContent=$('gain').value};
|
||
$('gain').onchange=pushLive;
|
||
$('auto_exp').onchange=()=>{
|
||
const manual=!$('auto_exp').checked;
|
||
$('exposure').disabled=!manual; $('gain').disabled=!manual;
|
||
pushLive();
|
||
};
|
||
|
||
// ---- 视频流设置(需重启)----
|
||
$('res').onchange=$('fps').onchange=()=>{
|
||
streamDirty=true;
|
||
$('applybtn').classList.add('dirty');
|
||
$('applybtn').textContent='应用视频流设置(未生效)';
|
||
};
|
||
async function applyStream(){
|
||
const [w,h]=$('res').value.split('x').map(Number);
|
||
$('applybtn').textContent='重启视频流中…';
|
||
const r=await api('/api/config',{width:w,height:h,fps:+$('fps').value});
|
||
streamDirty=false;
|
||
$('applybtn').classList.remove('dirty');
|
||
$('applybtn').textContent='应用视频流设置';
|
||
$('msg').textContent=r.error||'';
|
||
}
|
||
|
||
// ---- 录制 ----
|
||
async function toggleRec(){
|
||
if(st.on){ await api('/api/stop',{}); }
|
||
else{
|
||
const r=await api('/api/start',{
|
||
duration:+$('duration').value||0,
|
||
out_dir:$('out_dir').value.trim(),
|
||
save_depth:$('save_depth').checked});
|
||
$('msg').textContent=r.error||'';
|
||
}
|
||
poll();
|
||
}
|
||
|
||
// ---- 状态轮询 ----
|
||
async function poll(){
|
||
try{
|
||
st=await api('/api/status');
|
||
$('conn').textContent='已连接 · '+st.device;
|
||
$('conn').className='';
|
||
}catch(e){
|
||
$('conn').textContent='连接断开';
|
||
$('conn').className='bad';
|
||
return;
|
||
}
|
||
const b=$('recbtn');
|
||
b.disabled=!st.stream_ok;
|
||
if(st.on){
|
||
b.textContent='■ 停止并保存'; b.classList.add('rec');
|
||
let t=`录制中:<b>${st.frames}</b> 帧 · ${st.elapsed.toFixed(0)}s`;
|
||
if(st.duration>0) t+=` / ${st.duration}s(自动停止)`;
|
||
$('recinfo').innerHTML=t;
|
||
}else{
|
||
b.textContent='● 开始录制'; b.classList.remove('rec');
|
||
$('recinfo').innerHTML='';
|
||
}
|
||
$('saved').textContent=st.last_saved?('上次保存:'+st.last_saved):'';
|
||
$('ov_mode').textContent=`${st.width}×${st.height}@${st.fps}`;
|
||
$('ov_fps').textContent=`实际 ${st.fps_actual.toFixed(1)} fps`;
|
||
$('ov_depth').textContent=`深度有效 ${st.depth_fill.toFixed(0)}%`;
|
||
if(st.error) $('msg').textContent=st.error;
|
||
}
|
||
setInterval(poll,1000); poll();
|
||
</script>
|
||
</body>
|
||
</html>
|