openCV 2.4.3 iOS框架编译器无法识别一些c ++头文件 [英] openCV 2.4.3 iOS framework compiler trouble recognising some c++ headers

查看:1114
本文介绍了openCV 2.4.3 iOS框架编译器无法识别一些c ++头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

openCV 2.4.3 / Xcode 4.5.2 / mac osx 10.8.2



我想让openCV使用iOS。我试图使用来自openCV.org的预构建的2.4.3框架。但是,我得到以下xcode项目构建错误,建议编译器不知道它正在处理c ++,例如

  include< list> !'list'file not found 

namespace cv!unknown type name'namespace'

这似乎只关心以下头文件:

opencv2 / nonfree / features2d.hpp

opencv2 / nonfree / nonfree.hpp

opencv2 / video / video.hpp



如果我不在opencv.hpp(或其他任何地方)包含这三个文件,我似乎能够编译并使用openCV确定。麻烦的是,我确实需要非free文件,因为我正在试验SURF - 最近被移动到nonfree。



这是一个双重问题(对不起; - )




  • 我说服编译器这些是c ++头?


  • $ b

    更新 strong>



    我克隆了openCV git仓库,并从中构建了一个新的框架。这种方法以前没有工作,但今天我意识到,我没有使用当前版本的CMAKE。我一直在使用CMAKE 2.8.2,这将无法为ios构建opencv。当前版本CMAKE 2.8.10构建它没有任何问题(这是一个对象课程,在遵守文档,这说明CMAKE最低版本v2.8.8是必需的)。



    现在,当我在Xcode项目中添加opencv框架的当前构建时,可以包括 features2d nonfree 并建设顺利。唯一的问题仍然是一个标题: video / background_segm.hpp ,仍然会产生:

     code> #include< list>未找到'list'文件

    如果我评论在下一行中遇到错误:

     命名空间cv!未知类型名称'命名空间'

    看起来很清楚,编译器不会将其识别为C ++头文件,即使后缀为 .hpp



    opencv2 / video / video.hpp

      #includeopencv2 / video / background_segm.hpp

    我也可以使用 video.hpp 来构建(虽然我认为这在实践中是不可用的)。



    不幸的是我还是不能得到SURF的工作。当我运行的项目它崩溃与这个错误:


    OpenCV错误:功能/功能没有实现(OpenCV是建立没有SURF支持)


    这是在 legacy / features2d.cpp 中触发的:

      Ptr< Feature2D> surf = Algorithm :: create< Feature2D>(Feature2D.SURF); 
    if(surf.empty())
    CV_Error(CV_StsNotImplemented,OpenCV is built without SURF support);

    问题仍然存在...




    • 如何说服编译器 background_segm.hpp 是一个合法的c ++头?

    • 如何启用SURF支持?


    解决方案

    我现在有一切工作。在使用openCV.org提供的预构建的iOS库没有快乐之后,这是我做的...




    • compile从克隆的gitHub存储库的openCV for iOS。运行 build_framework.py (在分发的 ios 文件夹中),指向您选择的输出目录。


    • 您的输出文件夹将最终有两个子文件夹, build opencv2.framework 。将后者拖入您的Xcode项目




    project-Prefix中添加以下行。 pch 档案

      #ifdef __cplusplus 
    #import< opencv2 / opencv.hpp>
    #endif

    (应该在上方< $ c> #ifdef __OBJC __ 行)



    这足以使openCV的大部分工作。但是,避免objective-C ++(将c ++代码混合在与您的目标C相同的文件中)是一个非常好的主意。为了管理这个,你创建一个简单的包装器对象(它将是obj-C ++)来调停你的obj-c类和c ++代码。包装器基本上仅具有两个角色:翻译数据格式(例如UIImage_cv :: Mat),以及在obj-C方法和C ++函数调用之间翻译。有关详情,请参见我对此问题的回答 (和一个github托管的示例项目)



    要获得SURF(和SIFT)工作需要几个额外的步骤,因为SURF 由于许可问题而有所不同(已被移至 nonfree

    这些包括需要在使用SURF的文件中添加

      #include< opencv2 / nonfree / nonfree.hpp> 
    #include< Opencv2 / legacy / compat.hpp>

    我使用的代码使用SURF的C接口(例如 cvExtractSURF ),因此我们还需要在调用这些函数之前添加这一行:

      cv :: initModule_nonfree (); 

    我的问题的另一部分,如何强制Xcode编译为C ++,红鲱鱼(必须有一些与我使用的openCV构建的兼容性问题) - 并且不再需要这个解决方案。然而,答案是第一,重命名您的.m文件.mm(对于objective-C ++)或.cpp(纯C ++)...但如果这不工作,你可以强制在文件检查器中的问题更改'file类型。



    更新



    您还需要注意C ++标准库在使用openCV框架的任何项目中正确设置。旧版本的openCV(to.2.4.2)想要 libstdc ++ ,newer(2.4.3+)expect libc ++ 。详情如下:



    http://stackoverflow.com/a/14186883/ 1375695



    更新2



    openCV现在安装了cocoaPods。引用 SebastienThiebaud



    OpenCV在Cocoapods上可用。在您的Pod文件中添加一行:pod'OpenCV'。很容易。



    很简单...鉴于我们以前的麻烦,低调[最后]一年...


    openCV 2.4.3 / Xcode 4.5.2 / mac osx 10.8.2

    I am trying to get openCV working with iOS. I am attempting to use the the prebuilt 2.4.3 framework from openCV.org. However I am getting the following xcode project build errors that suggest the compiler doesn't know it is dealing with c++, eg

    #include <list>       !'list' file not found
    
    namespace cv          !unknown type name 'namespace'
    

    This only seems to concern the following header files:
    "opencv2/nonfree/features2d.hpp"
    "opencv2/nonfree/nonfree.hpp"
    "opencv2/video/video.hpp"

    if I don't include these three files in opencv.hpp (or anywhere else) I seem to be able to compile and use openCV ok. The trouble is, I do need the nonfree files as I am experimenting with SURF - which has been moved to nonfree recently.

    This is really a twofold question (sorry ;-)

    • how do I convince the compiler that these are c++ headers?
    • which headers exactly do I need to use SURF?

    update

    I have cloned the openCV git repository and built a new framework from that. This approach had not worked previously, but today I realised that I was not using the current version of CMAKE. I had been using CMAKE 2.8.2 and this would fail to build opencv for ios. Current version CMAKE 2.8.10 builds it without any issues (that's an object lesson in obeying the docs, which do say CMAKE min. v2.8.8 is required).

    Now when I add this current build of the opencv framework in an Xcode project I can include features2d and nonfree and build smoothly. The only problem remains with one header: video/background_segm.hpp, which still yields:

    #include <list>       !'list' file not found
    

    If I comment that line out I get an error on the next line:

    namespace cv          !unknown type name 'namespace'
    

    It seems clear that the compiler doesn't recognise this as a C++ header, even though it is suffixed .hpp.

    In opencv2/video/video.hpp if I remove

    #include "opencv2/video/background_segm.hpp"
    

    I can build with video.hpp also (although I guess it would be unusable in practice).

    Unfortunately I still can't get SURF to work. When I run the project it crashes with this error:

    OpenCV Error: The function/feature is not implemented (OpenCV was built without SURF support)

    This is triggered in legacy/features2d.cpp:

       Ptr<Feature2D> surf = Algorithm::create<Feature2D>("Feature2D.SURF");
       if( surf.empty() )
            CV_Error(CV_StsNotImplemented, "OpenCV was built without SURF support");
    

    The questions remain...

    • how do I convince the compiler that background_segm.hpp is a legit c++ header?
    • how do I enable SURF support?

    解决方案

    I have everything working now. After having no joy with the pre-built iOS library available from openCV.org this is what I did...

    • compile openCV for iOS from a clone of the gitHub repository. Run build_framework.py (in the ios folder of the distribution), pointing to an output directory of your choosing. Be sure to have an up-to-date copy of CMake or you will trip over like I did.

    • Your output folder will end up with two subfolders, build and opencv2.framework. Drag the latter into your Xcode project

    Add the following line in the project-Prefix.pch file

    #ifdef __cplusplus
    #import <opencv2/opencv.hpp>
    #endif
    

    (should go above the #ifdef __OBJC__ line)

    That is sufficient to get most of openCV working. However it is a very good idea to avoid "objective-C++" (mixing your c++ code in the same files as your objective-C). To manage this you create a thin "wrapper" object (which will be obj-C++) to mediate between your obj-C classes and c++ code. The wrapper essentially has only two roles: to translate data formats (eg UIImage <-> cv::Mat), and to translate between obj-C methods and C++ function calls. See my answer to this question for details (and a github-hosted example project)

    To get SURF (and SIFT) working requires a couple of additional steps, as SURF is somewhat deprecated due to licensing issues (it's been moved into nonfree which does not load automatically).

    These includes need to be added in files where you are using SURF

    #include <opencv2/nonfree/nonfree.hpp>
    #include <opencv2/legacy/compat.hpp>
    

    The code I am working with uses the C interfaces for SURF (eg cvExtractSURF), so we also need to add this line before calling these functions:

       cv::initModule_nonfree();
    

    The other part of my question, how to force Xcode to compile as C++, was a bit of a red herring (there must have been something compatibility issue with the openCV build I was using) - and is no longer required for this solution. However the answer is first, to rename your .m files .mm (for objective-C++) or .cpp (for pure C++) … but if that doesn't work, you can force the issue in the file inspector by changing 'file type'.

    update

    You also need to take care that the C++ standard library is set correctly in any projects that use the openCV framework. Older versions of openCV (to.2.4.2) want libstdc++, newer (2.4.3+) expect libc++. Details here:

    http://stackoverflow.com/a/14186883/1375695

    update 2

    openCV now installs with cocoaPods. To quote SebastienThiebaud

    OpenCV is available on Cocoapods. Add one line in your Podfile: pod 'OpenCV'. Pretty easy.

    "Pretty easy" ... given all our previous hassles, could be the understatement of [last] year...

    这篇关于openCV 2.4.3 iOS框架编译器无法识别一些c ++头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆