Maintaining code compatibility between OpenCV 2 and OpenCV 3

前端 未结 3 809
不知归路
不知归路 2021-02-15 16:14

My library currently uses OpenCV 2. Now, I am trying to compile the library to use OpenCV 3. It seems that some header files were moved and some constants were renamed. For exam

3条回答
  •  無奈伤痛
    2021-02-15 17:06

    I had the same problem a few months ago, and I have to contraddict Kiran: I got my relatively big project to build both with OpenCv 2 and 3. Being able to build with both 2 and 3 is very important in a project transition phase, especially because OpenCV 3 is not in stable version yet, and yet has amazing optimization features.

    Isn't cv::INTER_LINEAR defined both in OpenCV 2 (header imgproc/imgproc.hpp) and 3? You'll have to replace some constant names, add a couple of inclusions, but that won't be too hard.

    Regarding header inclusions, there's a way to find an including path compatible both for Opencv2 and 3.

    From the link Kiran posted:

    In OpenCV 3 we write

    #include "opencv2/core.hpp"
    

    instead of

    #include "opencv2/core/core.hpp"
    

    The old method should also work.


    Update
    In the new Release Candidate, it's reported they have improved compatibility between OpenCV 2.4 and 3.x

    Improved compatibility with OpenCV 2.4:

    • 2.4.11 now includes "opencv2/core.hpp" and other such headers in addition to standard "opencv2/core/core.hpp".
    • smart pointers (Ptr<>) can now be created in both 2.4 and 3.0 style (new ClassName(params) vs makePtr(params))
    • trained and stored stat models from opencv_ml 2.4 can now be loaded and used by opencv_ml 3.0 as-is.
    • the 2.4=>3.0 transition guide has been sketched: http://docs.opencv.org/master/db/dfa/tutorial_transition_guide.html

提交回复
热议问题