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

Allow custom filter to be passed in to constructors. Add SmoothDampFilter as an alternative. #338

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

jmschrack
Copy link
Contributor

  • Switched from OneEuroFilter to SmoothDampFilter. Video comparison
  • Controller can take a customFilter{filter,opts} parameter to allow users to use their own custom filters
  • Added a basic example three-filter.html to show passing custom filters.

@hiukim
Copy link
Owner

hiukim commented Feb 6, 2023

Hi @jmschrack, thanks for the hard work and sorry for the delay. I finally got a chance to try it out.

I realized there is a pretty big delay in the smoothDamp filter (using your default 0.1 smoothTime). If I tune the value down, it becomes jittery as well, but that make sense.

I'm trying to replicate a similar "jitter-delay" tradeoff with OneEuro. With beta=0.001, and minCutOff=0.001, it looks like the result is similar. Demo: https://youtube.com/shorts/6uEftY6tr78

@jmschrack
Copy link
Contributor Author

@hiukim
That looks pretty similar to me! However, I think exposing an interface to allow users to pass in their own custom filter algorithm is a useful addition. I can update this branch to use OneEuroFilter as the default, but I'd like to keep a reference to SmoothDampFilter exposed as well. I've noticed that SmoothDamp seems to do a slightly better job in worse conditions? But that could just be idiosyncrasies of my hardware and lighting. I often work with 3d models that extend out from the image target a significant distance, so the minute jitters are more noticeable in my use case.

Re: "pretty big delay in smoothDamp"
I use MindAR for some projects at work, and our User Acceptance testing reports that people greatly prefer some lag over jitteriness. It's "more gentle and easier to look at." However, that's just my use case. :)

I also tried benchmarking the two filters, and it looks like OneEuroFilter and SmoothDampFilter are roughly equivalent in terms of speed when it comes to operating on 16 element Matrices. (I used c++ to compare the two, since JS is notoriously tricky to get accurate readings.) Normally the two filters are pretty close to each other in timing with the occasional swings one way or the other.

@jmschrack jmschrack changed the title Switched filter from to SmoothDamp filter. Allow custom filter to be passed in to constructors. Allow custom filter to be passed in to constructors. Add SmoothDampFilter as an alternative. Mar 8, 2023
@jmschrack
Copy link
Contributor Author

@hiukim Any more thoughts on this?
I've changed it back to having OneEuroFilter be the default.

@BostonLeeK
Copy link

Test is for personal project, smooth looks more pretty. Thanks for suggestion!

@Ucodia
Copy link

Ucodia commented Dec 28, 2023

The result in the video looks pretty amazing to me and an obvious improvement. I really wish this was a potential option in Mind AR or at least had an option to provide your own custom filters. In my case, the default filter does nearly nothing, my image tracking is quite annoying to watch because of the amount of jitter I am getting, MinCF and Beta settings have no impact.

@hiukim any chance this could be considered again?

@jmschrack any potential instructions on how one could utilize your code in case this won't be merged? Really excellent work on this implementation!

@jmschrack
Copy link
Contributor Author

@Ucodia before going to a custom solution, have you tried beta=0.001; minCutOff=0.001 with the default filter? I find that is good enough majority of the time.

If that doesn't work and you want to try my custom filter setup, uninstall mindar from your project, and then install npm install "https://github.com/jmschrack/mind-ar-js.git#enhancement/customFilter_smoothDamp" and then check out the examples/image-tracking/three-filter.html to see how to pass a custom filter in.

Caveat: I just pulled in the master and fixed merge conflicts, but I don't have time right now to test it.

The main difference between the two filters is that OneEuroFilter can smooth out problems 90% of the time and is extremely performant. But it's that 10% that can seem awful. Whereas SmoothDamp is guaranteed smooth at the cost of increased overhead. However, when i've benchmarked the two against each other, SmoothDamping comes in pretty close to OneEuroFilter. (But benchmarking javascript is never super accurate.)

@Ucodia
Copy link

Ucodia commented Dec 29, 2023

@jmschrack I had attempted to use custom values for those parameters but I guess I was not using the appropriate combination. Setting filterMinCF:0.001; filterBeta: 0.001; resolved my issue and made my tracking super stable and usable. Thank you so much for your input 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants