Skip to content

Commit 553be2f

Browse files
Merge pull request #134 from JingyuanZhang/master
feat(example): update example humanstream
2 parents 7fa7a28 + a616cd9 commit 553be2f

File tree

5 files changed

+39
-12238
lines changed

5 files changed

+39
-12238
lines changed
297 KB
Loading

packages/paddlejs-examples/humanStream/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
</head>
4848
<body>
4949
<video id="video"></video>
50+
<img id="bainen" src="./bgImgs/bainen.png" style="display:none;"/>
5051
<div id="tool">
5152
<div id="video-tool" class="flex">
5253
<button id="start" type="btn">开始</button>

packages/paddlejs-examples/humanStream/index.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,10 @@ const loadingDom = document.getElementById('isLoading');
66
const video = document.getElementById('video') as HTMLVideoElement;
77
const videoToolDom = document.getElementById('video-tool');
88

9-
10-
const videoCanvas = document.querySelector('#demo') as HTMLCanvasElement;
119
const bgElement = document.createElement('div') as HTMLDivElement;
1210
const container = document.querySelector('body');
1311
container.appendChild(bgElement);
1412

15-
function makeBgDom() {
16-
bgElement.style.width = `${videoCanvas.width}px`;
17-
bgElement.style.height = `${videoCanvas.height}px`;
18-
19-
const imgURL = 'http://localhost:8866/bgImgs/bg.jpg';
20-
bgElement.style.backgroundImage = 'url("' + imgURL + '")';
21-
bgElement.style.backgroundRepeat = 'no-repeat';
22-
bgElement.style.backgroundSize = 'cover';
23-
bgElement.style.backgroundPosition = 'center';
24-
bgElement.style.marginTop = `${-videoCanvas.height}px`;
25-
}
2613
load();
2714

2815
// 视频开始播放,loading消失
@@ -41,16 +28,23 @@ videoToolDom.addEventListener('click', function (e: Event) {
4128
}
4229
});
4330

31+
const canvas1 = document.getElementById('demo') as HTMLCanvasElement;
32+
33+
const ctx = canvas1.getContext('2d');
34+
const img = new Image();
35+
img.src = './bgImgs/bg.jpg';
36+
img.onload = function () {
37+
ctx.drawImage(img, 0, 0, canvas1.width, canvas1.height);
38+
};
39+
4440
async function load() {
4541
await humanseg.load();
4642
camera = new Camera(video, {
4743
onFrame: async () => {
4844
const {
4945
data
5046
} = await humanseg.getGrayValue(video);
51-
const canvas1 = document.getElementById('demo') as HTMLCanvasElement;
5247
humanseg.drawHumanSeg(canvas1, data);
53-
makeBgDom();
5448
}
5549
});
5650
}

0 commit comments

Comments
 (0)