Skip to content

Commit 90f4853

Browse files
author
tianzhao
committed
remove preview
1 parent 74f563d commit 90f4853

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

main.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ <h3 style="display: inline-block; margin-right: 15px;">One Euro Filter 参数设
6262
</div>
6363
</div>
6464

65-
<video id="video" width="640" height="480" autoplay playsinline muted></video>
6665
<canvas id="canvas" width="640" height="480"></canvas>
6766
<script src="main.js"></script>
6867

main.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class PoseEstimator {
2-
constructor(videoElement, canvasElement) {
3-
this.video = videoElement;
2+
constructor(canvasElement) {
43
this.canvas = canvasElement;
54
this.ctx = this.canvas.getContext('2d');
5+
this.video = null; // 内部创建的video元素,不显示
66
this.detector = null;
77
this.poseFilters = null;
88
this.lastFilteredPose = null; // 用于存储上一帧的滤波结果
@@ -111,6 +111,14 @@ class PoseEstimator {
111111

112112
// 设置摄像头
113113
async _setupCamera() {
114+
// 创建隐藏的video元素用于获取摄像头流
115+
this.video = document.createElement('video');
116+
this.video.style.display = 'none';
117+
this.video.autoplay = true;
118+
this.video.playsInline = true;
119+
this.video.muted = true;
120+
document.body.appendChild(this.video);
121+
114122
const stream = await navigator.mediaDevices.getUserMedia({ 'video': true });
115123
this.video.srcObject = stream;
116124
await new Promise((resolve) => {
@@ -324,9 +332,8 @@ class PoseEstimator {
324332

325333
// --- Main Execution ---
326334
async function main() {
327-
const video = document.getElementById('video');
328335
const canvas = document.getElementById('canvas');
329-
const estimator = new PoseEstimator(video, canvas);
336+
const estimator = new PoseEstimator(canvas);
330337
await estimator.start();
331338
}
332339

0 commit comments

Comments
 (0)