Use of cv::Ptr to implement wrapper classes

asked 2019-03-27 07:36:20 -0500

HYPEREGO gravatar image

updated 2019-03-27 09:32:31 -0500

Hi all,

I'm writing a wrapper to handle every kind of Feature Extractor/Detector/Matcher plus adding someone new. Just to clarify, I'm doing this because I'm building a ROS node that can do feature matching (I don't it already exist something, the question isn't that eheh)

I can't understand how I can use cv::Ptr correctly. Since cv::Ptr have been defined as a template class, I always need to specify the type of if, right? But, all of feature detection/extraction algorithm are inherited from cv::Feature2D, so it can be correct use that as a type ( cv::Ptr<cv::Feature2D> for instance) and then calldynamicCast() before I use the object? What about cv::Ptr<cv::Algorithm> ??

To be more clear, I can do something like:

cv::Ptr<cv::Feature2D> getDetectorPtr()
   return cv::ORB::create();

//use of the function
cv::Ptr<cv::Feature2D> temp_ptr = getDetectorPtr();
cv::Ptr<cv::ORB> ORB_ptr = temp_ptr.dynamicCast<cv::ORB>();

And another question is, there is a possibility to initialize an empty pointer of type cv::Ptr<cv::feature2d>? Because otherwise if something is going wrong I don't know what to return and manage that.. Thank you everybody in advance, I'm asking before wasting time because otherwise I've to think to another solution and I neve used cv::Ptr in that way.

Have a nice day to everybody!

edit retag flag offensive close merge delete