-
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathexample_canvas.js
More file actions
54 lines (45 loc) · 1.84 KB
/
Copy pathexample_canvas.js
File metadata and controls
54 lines (45 loc) · 1.84 KB
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
const jsartoolkitNFT = require ('../../dist/ARToolkitNFT_node.js');
const { createCanvas, loadImage } = require('canvas');
const fs = require('fs');
// Polyfill for requestAnimationFrame in Node.js
global.requestAnimationFrame = function(callback) {
return setImmediate(callback);
};
global.cancelAnimationFrame = function(id) {
clearImmediate(id);
};
async function init() {
console.log(__dirname + '/camera_para.dat');
let arControllerNFT = new jsartoolkitNFT.ARControllerNFT(2000, 1500, '/camera_para.dat');
let ar = await arControllerNFT._initialize();
loadImage('pinball-demo.jpg').then((image) => {
console.log('image: ', image.width, image.height);
const canvas = createCanvas(image.width, image.height);
const ctx = canvas.getContext('2d');
ctx.drawImage(image, 0, 0, image.width, image.height);
const imgData = ctx.getImageData(0, 0, image.width, image.height);
ar.on('getNFTMarker', function(e){
console.log("NFT marker detected: ", e.data.marker);
});
const cameraMatrix = ar.getCameraMatrix();
ar.loadNFTMarker('DataNFT/pinball', function (id) {
console.log('marker id is: ', id);
ar.trackNFTMarkerId(id);
let marker = ar.getNFTData(id, 0);
console.log("cameraMatrix: ", cameraMatrix);
});
function processFrame() {
if (ar && typeof ar.process === 'function') {
ar.process(imgData.data);
}
requestAnimationFrame(processFrame);
}
processFrame();
// Save the canvas to a PNG file
const out = fs.createWriteStream(__dirname + '/output.png');
const stream = canvas.createPNGStream();
stream.pipe(out);
out.on('finish', () => console.log('The PNG file was created.'));
});
}
init();