Skip to content

Commit 26c89b1

Browse files
committed
docs(models): update humanseg models docs
1 parent ccd7091 commit 26c89b1

File tree

4 files changed

+66
-27
lines changed

4 files changed

+66
-27
lines changed

packages/paddlejs-examples/humanStream/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const canvas1 = document.getElementById('demo') as HTMLCanvasElement;
3535
const videoCanvas = document.createElement('canvas') as HTMLCanvasElement;
3636
const videoCanvasCtx = videoCanvas.getContext('2d');
3737
async function load() {
38-
await humanseg.load();
38+
await humanseg.load(true, true);
3939
camera = new Camera(video, {
4040
mirror: true,
4141
enableOnInactiveState: true,

packages/paddlejs-models/humanseg/README.md

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
# humanseg
44

5-
A real-time human-segmentation model. You can use it to change background. The output of the model is gray value. Model supplies simple api for users. Api drawHumanSeg can draw human segmentation, another one drawMask can draw the background without human.
5+
A real-time human-segmentation model. You can use it to change background. The output of the model is gray value. Model supplies simple api for users.
6+
7+
Api drawHumanSeg can draw human segmentation with a specified background.
8+
Api blurBackground can draw human segmentation with a blurred origin background.
9+
Api drawMask can draw the background without human.
610

711

812
# Usage
@@ -11,25 +15,40 @@ A real-time human-segmentation model. You can use it to change background. The o
1115

1216
import * as humanseg from '@paddlejs-models/humanseg';
1317

14-
// load humanseg model
18+
// load humanseg model, use 398x224 shape model, and preheat
1519
await humanseg.load();
1620

17-
// get the gray value [192 * 192];
21+
// use 288x160 shape model, preheat and predict faster with a little loss of precision
22+
// await humanseg.load(true, true);
23+
24+
// get the gray value [2, 398, 224] or [2, 288, 160];
1825
const { data } = await humanseg.getGrayValue(img);
1926

27+
// background canvas
28+
const back_canvas = document.getElementById('background') as HTMLCanvasElement;
29+
2030
// draw human segmentation
21-
const canvas1 = document.getElementById('demo1') as HTMLCanvasElement;
22-
humanseg.drawHumanSeg(canvas1, data);
31+
const canvas1 = document.getElementById('back') as HTMLCanvasElement;
32+
humanseg.drawHumanSeg(data, canvas1, back_canvas) ;
2333

24-
// draw the background mask
25-
const canvas2 = document.getElementById('demo2') as HTMLCanvasElement;
26-
humanseg.drawMask(canvas2, data, true);
34+
// blur background
35+
const canvas2 = document.getElementById('blur') as HTMLCanvasElement;
36+
humanseg.drawHumanSeg(data, canvas2) ;
37+
38+
// draw the mask with background
39+
const canvas3 = document.getElementById('mask') as HTMLCanvasElement;
40+
humanseg.drawMask(data, back_canvas, canvas3);
2741

2842
```
2943

44+
# Performance
45+
46+
<img width="800" src="https://user-images.githubusercontent.com/10822846/126873788-1e2d4984-274f-45be-8716-2a87ddda8c75.png"/>
47+
<img width="800" src="https://user-images.githubusercontent.com/10822846/126873838-e5b68c9b-279f-4cb4-ae90-6aaaecd06aa4.png"/>
3048

31-
# performance
3249

33-
<img width="350" src="https://user-images.githubusercontent.com/10822846/114897087-7fdb2d80-9e43-11eb-806d-fcf0198bc701.png"/>
34-
<img width="350" src="https://user-images.githubusercontent.com/10822846/114897193-96818480-9e43-11eb-82bc-6d4e073423e9.png"/>
35-
<img width="350" src="https://user-images.githubusercontent.com/10822846/115279515-6b679f80-a179-11eb-87d9-41f84dc02430.jpg"/>
50+
# Used in Video Meeting
51+
<p>
52+
<img width="400" src="https://user-images.githubusercontent.com/10822846/126872499-c3fd680e-a01b-4daa-b0cb-acd3290862bd.gif"/>
53+
<img width="400" src="https://user-images.githubusercontent.com/10822846/126872930-4f4c5c5d-5c51-44fe-b2d6-3f83c4e124bc.png"/>
54+
</p>

packages/paddlejs-models/humanseg/README_cn.md

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,52 @@
33
# 人像分割
44

55
实时的人像分割模型。使用者可以用于背景替换。需要使用接口 getGrayValue 获取灰度值。
6-
然后使用接口 drawHumanSeg 绘制分割出来的人像;也可以使用 drawMask 接口绘制背景,可以配置参数来获取全黑背景或者原图背景。
6+
然后使用接口 drawHumanSeg 绘制分割出来的人像,实现背景替换;使用接口 blurBackground 实现背景虚化;也可以使用 drawMask 接口绘制背景,可以配置参数来获取全黑背景或者原图背景。
77

88
# 使用
99

1010
```js
1111

12+
// 引入 humanseg sdk
1213
import * as humanseg from '@paddlejs-models/humanseg';
1314

14-
// 下载模型
15+
// 默认下载 398x224 shape 的模型,默认执行预热
1516
await humanseg.load();
1617

17-
// 获取灰度值
18+
// 指定下载更轻量模型, 该模型 shape 288x160,预测过程会更快,但会有少许精度损失
19+
// await humanseg.load(true, true);
20+
21+
22+
// 获取分割后的像素 alpha 值,大小为 [2, 398, 224] 或者 [2, 288, 160]
1823
const { data } = await humanseg.getGrayValue(img);
1924

20-
// 绘制分割出来的人像
21-
const canvas1 = document.getElementById('demo1') as HTMLCanvasElement;
22-
humanseg.drawHumanSeg(canvas1, data);
25+
// 获取 background canvas
26+
const back_canvas = document.getElementById('background') as HTMLCanvasElement;
27+
28+
// 背景替换, 使用 back_canvas 作为新背景实现背景替换
29+
const canvas1 = document.getElementById('back') as HTMLCanvasElement;
30+
humanseg.drawHumanSeg(data, canvas1, back_canvas) ;
31+
32+
// 背景虚化
33+
const canvas2 = document.getElementById('blur') as HTMLCanvasElement;
34+
humanseg.drawHumanSeg(data, canvas2) ;
2335

24-
// 绘制分割后的背景,第三个参数是是否使用 dark 模式,如果使用,背景为 黑色
25-
const canvas2 = document.getElementById('demo2') as HTMLCanvasElement;
26-
humanseg.drawMask(canvas2, data, true);
36+
// 绘制人型遮罩,在新背景上隐藏人像
37+
const canvas3 = document.getElementById('mask') as HTMLCanvasElement;
38+
humanseg.drawMask(data, back_canvas, canvas3);
2739

2840
```
41+
2942
# 效果
3043

31-
<img width="350" src="https://user-images.githubusercontent.com/10822846/114897087-7fdb2d80-9e43-11eb-806d-fcf0198bc701.png"/>
32-
<img width="350" src="https://user-images.githubusercontent.com/10822846/114897193-96818480-9e43-11eb-82bc-6d4e073423e9.png"/>
33-
<img width="350" src="https://user-images.githubusercontent.com/10822846/115279515-6b679f80-a179-11eb-87d9-41f84dc02430.jpg"/>
44+
从左到右:原图、背景虚化、背景替换、人型遮罩
45+
46+
<img width="800" src="https://user-images.githubusercontent.com/10822846/126873788-1e2d4984-274f-45be-8716-2a87ddda8c75.png"/>
47+
<img width="800" src="https://user-images.githubusercontent.com/10822846/126873838-e5b68c9b-279f-4cb4-ae90-6aaaecd06aa4.png"/>
48+
49+
50+
# 视频会议
51+
<p>
52+
<img width="400" src="https://user-images.githubusercontent.com/10822846/126872499-c3fd680e-a01b-4daa-b0cb-acd3290862bd.gif"/>
53+
<img width="400" src="https://user-images.githubusercontent.com/10822846/126872930-4f4c5c5d-5c51-44fe-b2d6-3f83c4e124bc.png"/>
54+
</p>

packages/paddlejs-models/humanseg/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ export async function preheat() {
6060

6161
export async function getGrayValue(input: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement) {
6262
inputElement = input;
63-
const res = await runner.predict(input);
64-
const seg_values = res;
63+
const seg_values = await runner.predict(input);
6564
backgroundSize = genBackgroundSize();
6665
return {
6766
width: WIDTH,

0 commit comments

Comments
 (0)