Maintaining code compatibility between OpenCV 2 and OpenCV 3

前端 未结 3 786
不知归路
不知归路 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 16:50

    EDIT:- Read Antonio's answer. You can include compatibility header types_c.h(1) and use OpenCV 2 constant names which works in OpenCV 3 also. This is since, even though constant names differ (e.g. INTER_LINEAR vs CV_INTER_LINEAR), constant values remain the same(2). So functions accepting integer const values should behave no different in OpenCV 2 and 3. Same is the case for other constants also. This way you just have to change header paths between OpenCV 2 and 3.

    OLD ANSWER:- This is not possible. OpenCV 3 is not completely backward compatible with OpenCV 2. You will have to change enums, header paths etc between OpenCV 2 and 3. See Changelog(3) for sections about backward compatibility.

    You could try things like copying headers around, giving numbers instead of constant names, using #ifdefs all over your code - but sooner or later that is going to fail. I suggest maintaining separate copies and have peace of mind. I would rather ignore OpenCV 2 altogether unless I am currently in production.

提交回复
热议问题