Skip to content

Instantly share code, notes, and snippets.

@vinooniv
Created April 30, 2020 02:15
Show Gist options
  • Save vinooniv/343dcfecde68a2ca9ed5e2ba91e048ca to your computer and use it in GitHub Desktop.
Save vinooniv/343dcfecde68a2ca9ed5e2ba91e048ca to your computer and use it in GitHub Desktop.
<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