保持OpenCV 2和OpenCV 3之间的代码兼容性 [英] Maintaining code compatibility between OpenCV 2 and OpenCV 3
问题描述
我的库当前使用的是OpenCV2.现在,我正在尝试编译该库以使用OpenCV3.似乎某些头文件已移动,某些常量已重命名.例如,在OpenCV 3中未定义CV_INTER_LINEAR
.
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 example, CV_INTER_LINEAR
is not defined in OpenCV 3.
由于我的库需要在OpenCV 2和3上编译并运行,是否有任何简单的方法来克服这种不兼容性?
我可以更改代码,但是在OpenCV 2中不起作用. /p>
As my library needs to be compiled and run on both OpenCV 2 and 3, Is there any simple way to overcome this incompatibility?
I can change my code, but then it doesn't work in OpenCV 2.
推荐答案
几个月前,我遇到了同样的问题,我不得不与Kiran矛盾:我有一个相对较大的项目,可以同时使用OpenCv 2和3进行构建.能够同时使用2和3进行构建在项目过渡阶段非常重要,尤其是因为OpenCV 3尚未处于稳定版本,并且具有惊人的优化功能.
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.
cv::INTER_LINEAR
在OpenCV 2(标头imgproc/imgproc.hpp
)和3中都没有定义吗?您必须替换一些常量名称,添加几个包含物,但这并不难.
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.
关于标头包含,有一种方法可以找到与Opencv2和3都兼容的包含路径.
Regarding header inclusions, there's a way to find an including path compatible both for Opencv2 and 3.
通过链接Kiran发布:
在OpenCV 3中,我们编写
In OpenCV 3 we write
#include "opencv2/core.hpp"
代替
#include "opencv2/core/core.hpp"
旧方法也应该起作用.
更新
在新版本候选人中,
Update
In the new Release Candidate, it's reported they have improved compatibility between OpenCV 2.4 and 3.x
改善了与OpenCV 2.4的兼容性:
Improved compatibility with OpenCV 2.4:
- 2.4.11现在除了标准的"opencv2/core/core.hpp"之外,还包括"opencv2/core.hpp"和其他此类标头.
- 智能指针(Ptr<>) 现在可以同时以2.4和3.0样式创建(新的ClassName(params)与 makePtr(params)) 来自的
- 训练和存储的统计模型 现在,opencv_ml 3.0可以按原样加载和使用opencv_ml 2.4.
- 已草绘2.4 => 3.0过渡指南: http://docs.opencv.org /master/db/dfa/tutorial_transition_guide.html
- 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
这篇关于保持OpenCV 2和OpenCV 3之间的代码兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!