2

I have downloaded a sample code of Java OpenCV. In few lines of the code there is FeatureDetectore() method that the compiler says it's deprecated.

    FeatureDetector detector = FeatureDetector.create(FeatureDetector.MSER);
    detector.detect(mGrey, keypoint);
    listpoint = keypoint.toList();

So, How should I replace this part of code? Are there any new alternative for this? or can I continue use of the deprecated function?

Hasani
  • 3,543
  • 14
  • 65
  • 125

2 Answers2

5

You can continue with this and this will work. Deprecation means that there is new recommended alternative, but off course old code will still work. The new way of doing that would be using FastFeatureDetector or AgastFeatureDetector depending on your use case. I am not familiar with OpenCV so unfortunately I can't recommend which exact implementation you need, you need to read JavaDoc/other docs and find out which would fit your code.

ctomek
  • 1,696
  • 16
  • 35
  • But ... as happens with deprecated features it is now gone. So old code no longer works. And this is not helpful as it simply says to read the docs. And the docs simply say "Please use direct instantiation of Feature2D classes" which is less than helpful IMO. – steve Apr 14 '23 at 22:44
4

By reading this documentation page , it is obvious that now we instantiate directly the required detector, such as:

Mat mask = new Mat();
MatOfKeyPoint keypoints = new MatOfKeyPoint();
MSER detector = MSER.create();
detector.detect(imageMat, keypoints, mask);

It is excatly the same for ORB, just change the class:

Mat mask = new Mat();
MatOfKeyPoint keypoints = new MatOfKeyPoint();
ORB detector = ORB.create();
detector.detect(imageMat, keypoints, mask);

Before deprecation we had to write something similar to (this is the OLD class ):

FeatureDetector _featureDetector = FeatureDetector.create(FeatureDetector.ORB);
Sameh Yassin
  • 424
  • 3
  • 9
  • Not sure that it's 'obvious' from the docs :), but this is the correct and helpful answer. – steve Apr 14 '23 at 23:00