Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding features track functionality to the project #7

Merged
merged 19 commits into from
May 15, 2024

Conversation

kalwalt
Copy link
Member

@kalwalt kalwalt commented Mar 25, 2023

Tracking feature

The code can only compute keypoints and descriptors for the trackable. I will implement also the tracking functionality.
This codes will be derived most from webarkit-testing and wasm-ar, even if they are coded with C++, i think it can be easily translated to js.
I will add inside WebARKitCV a track method, with a trackables argument and a Promise structure.
So you will be able to pass matrix data to trackers; it will be independent from any 3d is rendering library.

List of features:

  • track method.
  • Tracker class and ITracker interface.
  • simple VideoCapture method for video stream. cameraViewRenderer class for video stream to be exported
  • tracking code implemented inside the Worker, event listeners to pass data from/to.

For the future...

Things to improve in the near future.

  • We need to display correctly the found pattern, a sort of draw debug function to dispaly a rect around it.
  • improve the detection and tracking phase in the worker.
  • docker image to build the whole project.

@kalwalt kalwalt added the 🚀 enhancement New feature or request label Mar 25, 2023
@kalwalt kalwalt self-assigned this Mar 25, 2023
kalwalt added 6 commits March 25, 2023 21:45
- post vWidth and vHeight to the worker
- missed ConfigData
- increased number of ORB features
- disabled blurring for now
@@ -43,7 +43,12 @@ const loadTrackables = async (msg: any) => {
let src = msg.data;
let refRows = msg.trackableHeight;
let refCols = msg.trackableWidth;
let mat = new cv.matFromArray(refRows, refCols, cv.CV_8UC4, src);
Copy link
Member Author

Choose a reason for hiding this comment

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

This wasn't correct, infact logging the mat it gives me an Unbinding error, though i have no errors in the console.

//var mat = new cv.Mat(imageData.height, imageData.width, cv.CV_8UC4);
let mat = new cv.Mat(refRows, refCols, cv.CV_8UC4);
//mat.data.set(imageData.data);
mat.data.set(src.data);
Copy link
Member Author

Choose a reason for hiding this comment

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

i found this snippet from helpers.js opencv code, see matFromImageData:

Module['matFromImageData'] = function(imageData) {
    var mat = new cv.Mat(imageData.height, imageData.width, cv.CV_8UC4);
    mat.data.set(imageData.data);
    return mat;
};


let ksize = new cv.Size(BlurSize, BlurSize);
let anchor = new cv.Point(-1, -1);
cv.blur(mat, mat, ksize, anchor, cv.BORDER_DEFAULT);
//cv.blur(mat, mat, ksize, anchor, cv.BORDER_DEFAULT);
Copy link
Member Author

@kalwalt kalwalt Mar 26, 2023

Choose a reason for hiding this comment

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

Adding blur make more difficult to detect, i will leave out this, maybe i need to adjust the settings.

template_keypoints_vector = new cv.KeyPointVector();

template_descriptors = new cv.Mat();

let noArray = new cv.Mat();

let orb = new cv.ORB(3000);
let orb = new cv.ORB(10000);
Copy link
Member Author

Choose a reason for hiding this comment

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

Better to increase the number of features, it gives more matches.


let ksize = new cv.Size(BlurSize, BlurSize);
let anchor = new cv.Point(-1, -1);
cv.blur(src, src, ksize, anchor, cv.BORDER_DEFAULT);
//cv.blur(src, src, ksize, anchor, cv.BORDER_DEFAULT);
Copy link
Member Author

Choose a reason for hiding this comment

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

same as above.


var frame_keypoints_vector = new cv.KeyPointVector();

var frame_descriptors = new cv.Mat();

var orb = new cv.ORB();
var orb = new cv.ORB(10000);
Copy link
Member Author

Choose a reason for hiding this comment

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

same as above

@kalwalt
Copy link
Member Author

kalwalt commented Apr 5, 2023

cv.perspectiveTransform is wrapped in a different way from C++ it require cv.Mat as args, struglled a bit with this.
I implemented homographyValid method (not sure if it is correct) but fails with my image test, looks as something is not correct in the code, maybe the same code that can be used in C++ it's needed to adapt. Investigating on this.

@kalwalt
Copy link
Member Author

kalwalt commented May 15, 2024

regarding the last comment, when testing the example.html we get this error:

Worker.ts?./node_mod…-loader/index.js:68 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'doubleAt')
    at homographyValid (Worker.ts?./node_mod…ader/index.js:68:19)
    at track (Worker.ts?./node_mod…ader/index.js:157:9)
    at async process (Worker.ts?./node_mod…ader/index.js:99:20)

this error happens only with htat example because the homography is not valid (because at the start it's not recognizing any pattern), it's empty and that's why that message. This routine:

if (homographyValid(homography) == true) {
    var out = fill_output(cv, homography, valid);
  }

should be placed after the findHomography function. i will fix this.

@kalwalt
Copy link
Member Author

kalwalt commented May 15, 2024

In check if homograpy is valid commit testing the example_image the result is false. i think that something is not correct maybe this method should be different in javascript? I transformed this snippet from C++ code and maybe should be written in another way?
I wil merge this PR as i would mantain a small Pr's pattern, instead of a BIG one.
Updating the start of this PR thread with a to do list for the future.

@kalwalt kalwalt merged commit 446a655 into dev May 15, 2024
3 checks passed
@kalwalt kalwalt deleted the features-track-functionality branch May 15, 2024 13:10
@kalwalt kalwalt added ⌨️ Typescript About Typescript issues and related features 🔬 OpenCV Improvements to OpenCV code and building the source code labels May 17, 2024
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 ⌨️ Typescript About Typescript issues and related features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant