inspirit / jsfeat

JavaScript Computer Vision library.
MIT License
2.74k stars 374 forks source link

dense optical flow algorithm #57

Open hellochar opened 8 years ago

hellochar commented 8 years ago

Hey inspirit, awesome library. Any chance we could get a dense optical flow algorithm? I'm kinda hacking it right now by placing sparse points on a regular grid in my image, but of course it has its drawbacks. I poked around a bit and found https://github.com/anvaka/oflow/blob/master/dist/oflow.js which looks like it already has an implementation? Thanks!

gilborty commented 8 years ago

Hey @hellochar, I don't think the code you linked implements a dense optical flow algorithm. Actually, it seems like it uses Lucas-Kande which jsfeat has already implemented here with the demo here.

With that being said, dense optical flow algorithms such as Gunner Farneback's algorithm tend to run very slow using only the CPU because they, in short, calculate flow for all of the pixels instead of only some as is the case with sparse optical flow algorithms. Check out this page for an example using OpenCV. However, dense optical flow algorithms can actually run close to real-time if you offload the calculations to a GPU. If you intend to implement your own, in JavaScript, might I suggest using Three-js and check out the WebGL examples.