Skip to content

Commit

Permalink
trying to improve the webcam example
Browse files Browse the repository at this point in the history
  • Loading branch information
kalwalt committed Dec 4, 2024
1 parent 74d2fcf commit 7e5d992
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 30 deletions.
2 changes: 1 addition & 1 deletion dist/src/Workers/WebARKitCVWorkers.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/core/WebARKitCoreCV.js.map

Large diffs are not rendered by default.

40 changes: 18 additions & 22 deletions dist/src/core/WebARKitCoreCV2.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/src/core/WebARKitCoreCV2.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/webarkitCV.js

Large diffs are not rendered by default.

38 changes: 34 additions & 4 deletions examples/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
var video = document.getElementById('video');

const cameraView = new WebARKitCV.CameraViewRenderer(video);
console.log(cameraView)

var videoSettingData = {
width: { min: 640, max: 800 },
Expand All @@ -26,23 +27,52 @@
targetFrameRate: 60
}

var oWidth = 320;
var oHeight = 240;

const webarkit = new WebARKitCV.WebARKitCV(video);
var overlayCanvas;
createOverlayCanvas();

webarkit.setWidth(640)
.setHeight(480)
webarkit.setWidth(320)
.setHeight(240)
.addTrackable("pinball", "./pinball.jpg")
.loadTrackables()

const track = webarkit.build();

cameraView.initialize(videoSettingData).then(() => {
console.log(cameraView.getImage())
if (track.isLoaded) {
webarkit.track(track.trackers, cameraView.image).then((t) => {
console.log(t);
webarkit.track(track.trackers, cameraView.getImage()).then((t) => {
console.log('tracker: ', t);
window.addEventListener("getMatrix", function (e) {
console.log(e.detail);
drawOverlay(e.detail.finalImage);
})
})
}
})

function createOverlayCanvas() {
overlayCanvas = document.createElement("canvas");
setVideoStyle(overlayCanvas);
overlayCanvas.id = "overlay";
overlayCanvas.width = oWidth;
overlayCanvas.height = oHeight;
overlayCanvas.style.zIndex = 1;
document.body.appendChild(overlayCanvas);
}
function drawOverlay(imageData) {
const overlayCtx = overlayCanvas.getContext("2d");
overlayCtx.putImageData(imageData, 0, 0);
}
function setVideoStyle(elem) {
elem.style.position = "absolute";
elem.style.top = 0;
elem.style.left = 0;
}

</script>

</body>
Expand Down
1 change: 1 addition & 0 deletions src/core/WebARKitCoreCV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class WebARKitCoreCV {
}

track(msg: any) {
console.log("Tracking...", msg);
const imageData = new ImageData(
new Uint8ClampedArray(msg.imagedata),
msg.vWidth,
Expand Down

0 comments on commit 7e5d992

Please sign in to comment.