alemart / speedy-vision

GPU-accelerated Computer Vision for JavaScript.
Apache License 2.0
172 stars 28 forks source link

Feature detection odd behavior when not in a loop #4

Closed YoussefSbeiti closed 4 years ago

YoussefSbeiti commented 4 years ago

Executing the chunck of code: let media = await Speedy.load(canvas); features = await media.findFeatures({ method: 'fast',
sensitivity: 0.7 }); features would just be an empty array.

So I tried doing the following: let media = await Speedy.load(canvas); features = [] while(features.length == 0){ features = await media.findFeatures({ method: 'fast',
sensitivity: 0.7 }); }

but I noticed that it still doesn't detect all of the features in the image. I tried to play around with the sensitivity and expected value and noticed that the detection doesn't go all the way to the bottom of the image. It works fine when it's in a render loop.

Results can be seen in the images: In a render loop: Screenshot 2020-09-15 125652

Without render loop: Screenshot 2020-09-15 125800

Note: I am rendering the features on a different canvas than the one the image is drawn on.

alemart commented 4 years ago

Hello, @YoussefSbeiti. Thank you for your interest in this project. How did you find it? Could you clarify what your use case is? As this is a new project, I'm seeking to understand who its users are and what they are looking for.

When loading your media, Speedy will optimize things for either dynamic usage (videos & animations) or static usage (images). Dynamic usage gives you a performance boost when dealing with animations, but is unsuitable for static images unless you run it in a loop (which seems to be your case).

The behavior you have observed arises because, when loading a canvas, Speedy will assume dynamic usage by default. It doesn't know a priori whether the canvas is animated or not. Since you're detecting features in an image, you may either use a <img> tag instead of a canvas or keep the canvas but force static usage as follows:

let media = await Speedy.load(canvas, {
    usage: 'static'
});

Read more at SpeedyMedia.options. You may also take a look at the Hello World demo.

YoussefSbeiti commented 4 years ago

Thanks for the fast reply @alemart .It seems to have I am planning on using the project for my image processing class. I don't have a specific use case so far, I am just trying the library out.

alemart commented 4 years ago

Cool. You may find the Feature detection in an image demo to be helpful.

Get the latest speedy-vision.js from the master branch and have fun.