File size: 994 Bytes
709edf5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

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();
}