Created
April 30, 2020 02:15
-
-
Save vinooniv/343dcfecde68a2ca9ed5e2ba91e048ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<!-- Load Tensorflow and BodyPix --> | |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.2"></script> | |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/body-pix@2.0"></script> | |
</head> | |
<body> | |
<img hidden id='image' src='/img/sample.jpg' /> | |
<canvas id="canvas"></canvas> | |
</body> | |
<script> | |
const img = document.getElementById('image'); | |
const canvas = document.getElementById('canvas'); | |
async function loadAndBlur() { | |
const net = await bodyPix.load(); | |
const segmentation = await net.segmentPerson(img); | |
const backgroundBlurAmount = 9; | |
const edgeBlurAmount = 3; | |
const flipHorizontal = false; | |
bodyPix.drawBokehEffect(canvas, img, segmentation, backgroundBlurAmount, edgeBlurAmount, flipHorizontal); | |
} | |
loadAndBlur(); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment