-
Notifications
You must be signed in to change notification settings - Fork 0
/
3d.js
43 lines (37 loc) · 1.3 KB
/
3d.js
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
const videoElement = document.getElementsByClassName('input_video')[0]
const canvasElement = document.getElementsByClassName('output_canvas')[0]
const canvasCtx = canvasElement.getContext('2d')
function onResults (results) {
canvasCtx.save()
canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height)
if (!!results.objectDetections) {
for (const detectedObject of results.objectDetections) {
// Reformat keypoint information as landmarks, for easy drawing.
// const landmarks: mpObjectron.Point2D[] = detectedObject.keypoints.map(x => x.point2d)
const landmarks = detectedObject.keypoints.map(x => x.point2d)
// Draw bounding box.
window.drawConnectors(canvasCtx, landmarks, window.BOX_CONNECTIONS, { color: '#FF0000' })
// Draw centroid.
window.drawLandmarks(canvasCtx, [landmarks[0]], { color: '#FFFFFF' })
}
}
canvasCtx.restore()
}
const objectron = new Objectron({
locateFile: (file) => {
return `https://cdn.jsdelivr.net/npm/@mediapipe/objectron/${file}`
}
})
objectron.setOptions({
modelName: 'Cup',
maxNumObjects: 3,
})
objectron.onResults(onResults)
const camera = new Camera(videoElement, {
onFrame: async () => {
await objectron.send({ image: videoElement })
},
width: 640,
height: 480
})
camera.start()