Skip to content

Conversation

@kalwalt
Copy link
Member

@kalwalt kalwalt commented Oct 21, 2024

This pull request introduces several significant improvements and updates across the codebase, focusing on enhanced example usage, improved robustness in tracking, developer experience upgrades, and modernization of the build environment. The main changes include new and improved example HTML/CSS for demos, better error handling and validation in the tracking logic, and updates to dependencies and CI workflows to use more recent Node.js and Ubuntu versions.
Thus this PR try to implement the 2 point of issue #8.

Example and Demo Improvements:

  • Added a new CSS file (nft-style.css) and updated example HTML files to provide a more modern, visually appealing, and functional demo experience, including overlay canvases for drawing tracking results and improved event handling for detected markers. [1] [2] [3] [4]

Robustness and Error Handling in Tracking:

  • Improved the WebARKitCV class to validate image data before processing, skip invalid trackables, and provide a stopTracking method to cleanly cancel animation frames. [1] [2] [3] [4]
  • Enhanced the WebARKitCVOrbWorker to validate ImageData buffer sizes before posting to the worker, improving debugging and preventing subtle errors. Also updated the worker's message handling for better state management. [1] [2] [3] [4] [5]

Developer Experience and Testing:

  • Added a mock for the uuid module and introduced a new Jest ESM configuration for improved and more flexible testing. [1] [2]

Build and Dependency Updates:

  • Updated various devDependencies and dependencies to more recent versions, including uuid, TypeScript, Jest, Babel, Webpack, and others. [1] [2]

CI and Workflow Modernization:

  • Updated GitHub Actions workflows to use Node.js 22.13.x and Ubuntu 24.04 for both CI and build workflows, ensuring compatibility with newer environments. [1] [2]

Final note
Even it's not completely implemented the features of the main title, now the two examples can detect and track the images provided.

@kalwalt kalwalt added 🚀 enhancement New feature or request 🔬 OpenCV Improvements to OpenCV code and building the source code labels Oct 21, 2024
@kalwalt kalwalt self-assigned this Oct 21, 2024
@kalwalt
Copy link
Member Author

kalwalt commented Dec 3, 2024

with the testing class WebARKItCOreCV2 i'am on the right path, at least we have a debug image in the example_image.html

@kalwalt
Copy link
Member Author

kalwalt commented Dec 4, 2024

The simple example example.html will not works because the imageData is not continuosly updated, until i will not improve that it worth to focus on other aspects.

@kalwalt
Copy link
Member Author

kalwalt commented Dec 6, 2024

with the commit 48bdfd6 the example_image example doesn't works, I need to understand what bug was introduced...

- some small improves
- it can detect and track (image example)
- make AbstractWebARKitCVWorker constructor protected
- a bunch of readonly properties
@kalwalt
Copy link
Member Author

kalwalt commented Mar 22, 2025

the image_example can detect the face pattern and we can see the descriptors and the three red, green, blu line onto the image, we get at the end this error:

Uncaught TypeError: Cannot read properties of undefined (reading '$$')
    at GI.oI [as toWireType] (999068ed-ca1d-4048-a091-a096c233a195:1:5141060)
    at Object.calcOpticalFlowPyrLK (eval at aI (999068ed-ca1d-4048-a091-a096c233a195:1:5142885), <anonymous>:7:26)
    at CI.A.<computed> [as calcOpticalFlowPyrLK] (999068ed-ca1d-4048-a091-a096c233a195:1:5138750)
    at i.estimateCameraPosition (999068ed-ca1d-4048-a091-a096c233a195:1:5180424)
    at i.track (999068ed-ca1d-4048-a091-a096c233a195:1:5180124)
    at R (999068ed-ca1d-4048-a091-a096c233a195:1:5185877)
    at D.onmessage (999068ed-ca1d-4048-a091-a096c233a195:1:5185740)Understand this errorAI
lockdown-install.js:1 SES_UNCAUGHT_EXCEPTION: null

but i think can be easily solved.
Instead the example with the webcam stream can not detect the pinball image. It seems that the Worker never receive the imagedata from the outside. I think there is some inconsistencies in the WebARKitCVCore code. When i will get back from holydays i will develop a video file example, that maybe will avoid these issues.

@kalwalt
Copy link
Member Author

kalwalt commented Mar 22, 2025

The problem with the webcam example is that in the track method:

track(msg: any) {
console.log("Tracking...", msg);
if (!msg.imagedata) {
return;
}
console.log("msg-imagedata while Tracking...", msg.imagedata);
const imageData = new ImageData(
new Uint8ClampedArray(msg.imagedata),
msg.vWidth,
msg.vHeight,
);
return this.estimateCameraPosition({ id: 0, imageData: imageData });
}

we are providing wrong width and height params (in this case 1280 720) but imagedata is filled witha canvas with 320 and 240 height... we should provide these values in the builder with setWidth and setHeight methods
webarkit.setWidth(oWidth)
.setHeight(oHeight)
.addTrackable("pinball", "./pinball.jpg")
.loadTrackables()

i should move this block inside the camera initialization
cameraView.initialize(videoSettingData).then(() => {

- Add drawCorners method to draw polygon and corner markers on processing canvas
- Add tests/CameraViewRenderer.test.js to validate drawing calls using mocked context

Small, defensive change that doesn't affect existing behaviour. Tests pass.
- Added logging of camera view initialization for debugging purposes.
- Improved ImageData construction by dynamically handling width and height based on incoming message data, with fallbacks for mismatched buffer lengths.
- Implemented robust error handling in optical flow calculations to prevent crashes and ensure graceful degradation in tracking performance.
- Introduced a new method `drawCorners` in CameraViewRenderer to visualize detected corners on the processing canvas.
Updated the message sent to the worker to include the actual width and height of the ImageData. This ensures that the worker can reconstruct the ImageData accurately as produced by the renderer, improving processing accuracy.
- Improved logging for 'getMatrix' and 'lostMarker' events in example HTML files to provide clearer context.
- Added corner drawing functionality in the overlay for better visual feedback when corners are detected.
- Implemented buffer size validation in WebARKitCVWorkers to catch mismatches early, preventing potential errors in processing.
- Enforced strict validation of ImageData buffer lengths in WebARKitCoreCV2, eliminating silent failures and improving debugging.
…me rate control

- Added methods to set image size preservation and target frame rate in CameraViewRenderer.
- Updated example.html to utilize new camera settings for improved performance.
- Enhanced Worker.ts to handle marker results more robustly.
- Improved image data handling in WebARKitCoreCV2.ts for better memory management.
- Added tests for CameraViewRenderer to ensure correct behavior with image size preservation.
…tions

- Deleted the implementation of WebARKitCoreCV from WebARKitCoreCV.ts.
- Updated the type definitions in WebARKitCoreCV.d.ts to reflect the removal of the implementation.
- Adjusted the visibility of class properties and methods in the type definitions for clarity.
- Added stopTracking method in WebARKitCV class to cancel ongoing animation frames.
- Updated startTracking method to call stopTracking before initiating tracking.
- Modified example_image.html to call webarkit.stopTracking() after drawing the overlay.
- Updated TypeScript definitions to include the new stopTracking method.
- Updated devDependencies in package.json to latest versions.
- Added ESM tests for Trackable, Tracker, and WebARKitCVBuilder classes.
- Created tsconfig.jest.esm.json for ESM compatibility in Jest tests.
@kalwalt kalwalt requested a review from Copilot October 27, 2025 15:38
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request enhances the WebARKitCV library by improving homography computation, adding corner visualization capabilities, and updating project dependencies. The changes primarily focus on refactoring the core computer vision logic to use a more modern approach with optical flow tracking, implementing methods to draw detected corners, and upgrading various development dependencies.

Key changes:

  • Refactored WebARKitCoreCV to use optical flow tracking with solvePnP for improved pose estimation
  • Added drawCorners method to CameraViewRenderer for visualizing detected marker corners
  • Updated development dependencies including TypeScript, Babel, Jest, and build tools to newer versions

Reviewed Changes

Copilot reviewed 20 out of 53 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/core/WebARKitCoreCV.ts Major refactoring to implement optical flow tracking, keypoint matching, and projection matrix computation
src/io/CameraViewRenderer.ts Added corner drawing functionality and improved image caching mechanism
src/Workers/WebARKitCVWorkers.ts Enhanced worker message handling to include corners and processed image data
src/Workers/Worker.ts Updated message processing logic and improved error handling
src/WebARKitCV.ts Added tracking lifecycle management with stopTracking method
package.json Updated multiple dependencies to latest versions
examples/example.html Implemented overlay canvas for visualizing tracking results
examples/example_image.html Added corner drawing and overlay visualization functions
tests/CameraViewRenderer.test.js Added tests for drawCorners method
tests-esm/*.ts Added ESM-specific tests for builder, tracker, and trackable classes
jest.esm.config.cjs New Jest configuration for ESM testing
tsconfig.jest.esm.json New TypeScript configuration for ESM tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

kalwalt and others added 6 commits October 27, 2025 16:43
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Added validation for the received tracking data ID to ensure it corresponds to an existing memory entry.
- Implemented a warning log when tracking data is received for an ID without a corresponding memory entry.
- Updated the call to estimateCameraPosition to use the validated ID instead of a hardcoded value.
- Changed imageDataCache type from ImageData to Uint8ClampedArray for improved performance.
- Introduced cachedImageData to hold ImageData instances for rendering.
- Updated logic to invalidate caches when processing dimensions change.
- Modified updateImageCache method to handle new caching strategy.
- Adjusted getCachedImage method to return cachedImageData correctly.
@kalwalt kalwalt merged commit b583436 into dev Oct 27, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔬 OpenCV Improvements to OpenCV code and building the source code 🚀 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants