@@ -6,23 +6,10 @@ const loadingDom = document.getElementById('isLoading');
66const video = document . getElementById ( 'video' ) as HTMLVideoElement ;
77const videoToolDom = document . getElementById ( 'video-tool' ) ;
88
9-
10- const videoCanvas = document . querySelector ( '#demo' ) as HTMLCanvasElement ;
119const bgElement = document . createElement ( 'div' ) as HTMLDivElement ;
1210const container = document . querySelector ( 'body' ) ;
1311container . 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- }
2613load ( ) ;
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+
4440async 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