Spaces:
Runtime error
Runtime error
| let capture; | |
| let font; | |
| let segmenter; | |
| let people; | |
| let model; | |
| const canvas = document.getElementById('canvas'); | |
| let ctx = canvas.getContext('2d'); | |
| function setup() { | |
| createCanvas(640, 480); | |
| capture = createCapture(VIDEO, initModel); | |
| capture.hide(); | |
| background(255); | |
| } | |
| async function initModel() { | |
| model = await deeplab.load({ "base": 'pascal', "quantizationBytes": 2 }); | |
| } | |
| async function predict() { | |
| console.log('ok') | |
| segmenter = await model.segment(capture.elt); | |
| renderPrediction(segmenter); | |
| } | |
| function renderPrediction(prediction) { | |
| const { legend, height, width, segmentationMap } = prediction; | |
| //console.log(`prediction: ${JSON.stringify(prediction)}`); | |
| let segmentationMapData = new ImageData(segmentationMap, width, height); | |
| //console.log(segmentationMapData) | |
| ctx.putImageData(segmentationMapData, 0, 0); | |
| } | |
| function draw() { | |
| background(0,1); | |
| if (model) { | |
| predict(); | |
| console.log('ok') | |
| } | |
| } | |
| function keyPressed() { | |
| noLoop(); | |
| } | |