@@ -8,6 +8,7 @@ const videoToolDom = document.getElementById('video-tool');
88
99const bgElement = document . createElement ( 'div' ) as HTMLDivElement ;
1010const container = document . querySelector ( 'body' ) ;
11+
1112container . appendChild ( bgElement ) ;
1213
1314load ( ) ;
@@ -30,25 +31,22 @@ videoToolDom.addEventListener('click', function (e: Event) {
3031
3132const canvas1 = document . getElementById ( 'demo' ) as HTMLCanvasElement ;
3233
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- } ;
3934
35+ const videoCanvas = document . createElement ( 'canvas' ) as HTMLCanvasElement ;
36+ const videoCanvasCtx = videoCanvas . getContext ( '2d' ) ;
4037async function load ( ) {
41- await humanseg . load ( ) ;
38+ await humanseg . load ( true , true ) ;
4239 camera = new Camera ( video , {
40+ mirror : true ,
41+ enableOnInactiveState : true ,
4342 onFrame : async ( ) => {
43+ videoCanvas . width = video . width ;
44+ videoCanvas . height = video . height ;
45+ videoCanvasCtx . drawImage ( video , 0 , 0 , video . width , video . height ) ;
4446 const {
4547 data
46- } = await humanseg . getGrayValue ( video ) ;
47- humanseg . drawHumanSeg ( canvas1 , data ) ;
48+ } = await humanseg . getGrayValue ( videoCanvas ) ;
49+ humanseg . blurBackground ( data , canvas1 ) ;
4850 }
49- // canvas大小不合适可以自行修改width,height
50- // width: 800,
51- // height: 600
5251 } ) ;
5352}
54-
0 commit comments