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

[Feature] Add getter/setter in Feature2D algorithms #906

Open
cronsin opened this issue Dec 13, 2023 · 0 comments
Open

[Feature] Add getter/setter in Feature2D algorithms #906

cronsin opened this issue Dec 13, 2023 · 0 comments
Assignees

Comments

@cronsin
Copy link

cronsin commented Dec 13, 2023

Describe the feature
In OpenCV, when we look at Feature2D algorithms (like FAST (https://docs.opencv.org/3.4/df/d74/classcv_1_1FastFeatureDetector.html), ORB (https://docs.opencv.org/3.4/db/d95/classcv_1_1ORB.html) or LUCID (https://docs.opencv.org/4.x/d4/d86/classcv_1_1xfeatures2d_1_1LUCID.html)), there's a lot of get/set accessors (like getThreshold/setThreshold for FAST) which are not available at all throught EMGU.

For performance reason, these accessors must be available in at least one of the following way :

  • Directly as a property on algorithm's classes (<= This one is the way that makes more sense but more time-consuming to develop)
  • Throught some static method in classes like "Features2DInvoke".
  • At least, as an exposed entry point in cvextern.dll so we (consumer of emgu library) can do P/Invoke onto this entry point (<= This one is the least time-consuming, since it requires only c++ side to be updated.)

Performance is critical here. These algorithms are compute intensive code which may be used in scenarios were an enduser experience will be reduced if we don't pay attention to micro-optimization.

** OS / Platform **
All

** .Net version **
All

CPU Architecture
All

** Emgu CV package used**
Emgu.CV.runtime.windows-4.7.0.5276 nuget package from commercial repository.

To Reproduce
When we try to avoid new object creation/native memory structure initialization :

Emgu.CV.Features2D.FastFeatureDetector detector = new Emgu.CV.Features2D.FastFeatureDetector();
for(int threshold = 0; threshold < 64; threshold++) {
  FileStorage storage = new FileStorage("dontcare.json", FileStorage.Mode.FormatJson | FileStorage.Mode.Write | FileStorage.Mode.Read | FileStorage.Mode.Memory);//Must allocate inmemory file storage = time & memory consuming.
  detector.Write(storage);//May expand underlying storage = even more time & memory lost.
  var rawConfig = storage.ReleaseAndGetString();//Releasing resources = time consuming.
  //Parse the rawConfig into Json object = time consuming.
  //Lookup for corresponding property for "threshold" parameter = time consuming.
  //Load back the new configuration into detector (JSON object => String serialization => FileStorage) = Even more time & memory lost.
  var keypoints = detector.Detect(someImageHere);//...Detect features...
  if (keypoints.Length >= settings.MinimumKeyPointCountSetting) {
     //Do some stuff when minimal keypoint count is met so we have better results in the remaining code here.
  }
}

When we try to avoid all time & memory losses spent in some bytes<->string<->object<->string<->bytes conversions :

for(int threshold = 0; threshold < 64; threshold++) {
  Emgu.CV.Features2D.FastFeatureDetector detector = new Emgu.CV.Features2D.FastFeatureDetector(threadhold: threshold);//Re-allocation of underlying native memory by calling one of the OpenCV's FAST initialization routine => Time & memory consuming.
  var keypoints = detector.Detect(someImageHere);//...Detect features...
  if (keypoints.Length >= settings.MinimumKeyPointCountSetting) {
     //Do some stuff when minimal keypoint count is met so we have better results in the remaining code here.
  }
}

Expected behavior

Emgu.CV.Features2D.FastFeatureDetector detector = new Emgu.CV.Features2D.FastFeatureDetector();
for(int threshold = 0; threshold < 64; threshold++) {
  detector.Threshold = threshold;//Try at this threshold...It's the minimal time & memory losses solution => No memory (re)-allocation is done. The only remaining losses are related to P/Invoke or inner FAST implementation. Both of those can't be avoided.
  var keypoints = detector.Detect(someImageHere);//...Detect features...
  if (keypoints.Length >= settings.MinimumKeyPointCountSetting) {
     //Do some stuff when minimal keypoint count is met so we have better results in the remaining code here.
  }
}
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

No branches or pull requests

2 participants