-
Notifications
You must be signed in to change notification settings - Fork 5
/
3_object-detection.html
46 lines (39 loc) · 1.37 KB
/
3_object-detection.html
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
<!doctype html>
<html>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]"> </script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/[email protected]"> </script>
<style>
#img{
position: absolute;
left: 0;
top: 0;
}
</style>
<body>
<img id="img" crossorigin src="https://raw.githubusercontent.com/tensorflow/tfjs-models/master/coco-ssd/demo/image1.jpg" />
</body>
<script>
const img = document.getElementById('img');
img.onload = async () => {
cocoSsd.load().then(model => {
model.detect(img).then(predictions => {
console.log('Predictions: ', predictions);
drawObjectBoxes(predictions)
});
});
}
function drawObjectBoxes(predictions) {
for (pred of predictions) {
const square = document.createElement('div')
square.style.border = "1px solid red"
square.style.position = "absolute"
square.style.left = pred.bbox[0] + 'px'
square.style.top = pred.bbox[1] + 'px'
square.style.width = pred.bbox[2] + 'px'
square.style.height = pred.bbox[3] + 'px'
square.innerText = pred.class
document.body.appendChild(square)
}
}
</script>
</html>