【问题标题】:OpenCV compiler error when using Stitcher under iOS在 iOS 下使用 Stitcher 时的 OpenCV 编译器错误
【发布时间】:2012-10-24 17:33:04
【问题描述】:

每当我尝试在 iOS 中使用 OpenCV Stitcher 类并包含stitcher-header (#include) 时,都会在expected_compensate.hpp 中出现编译错误“Expected '{'”。显然这条线 枚举{不,增益,增益块}; 导致某种错误。

我对 openCV 很陌生,但使用 filter2d() 等其他功能可以按预期工作。我该如何解决这个问题?

【问题讨论】:

  • 请问你是怎么解决的

标签: ios opencv compiler-construction


【解决方案1】:

试试

#import <opencv2/opencv.hpp>

然后

#import <UIKit/UIKit.h>

更新:这个答案只突出了问题的最低限度的解决方案,也许是根本原因:依赖关系的顺序。请参阅其他答案以获得您在项目中添加的更好的代码/设置。

【讨论】:

  • 这在调试数小时后救了我。
  • 要获得更强大的解决方案,您绝对应该使用 PCH 文件,如其他答案中所述。
【解决方案2】:

在您的项目中,创建一个 Prefix Header MyProject.pch,并将其设置在您项目的构建设置中。

然后在该 pch 文件中,执行以下操作:

#ifdef __cplusplus
#   include <opencv2/opencv.hpp>
#   include <opencv2/stitching/detail/blenders.hpp>
#   include <opencv2/stitching/detail/exposure_compensate.hpp>
#else
#   import <Foundation/Foundation.h>
#   import <UIKit/UIKit.h>
#   import <Availability.h>
#endif

【讨论】:

    【解决方案3】:

    我也遇到了这个问题。作为 G. Führ 确保您首先包含 opencv 标头。最简单的方法是添加:

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

    靠近应用顶部的“Appname-Prefix.pch”标题。这是一个预编译的头文件,可以轻松保证您的 opencv 头文件将包含在任何苹果头文件之前。

    //
    //  Prefix header
    //
    //  The contents of this file are implicitly included at the beginning of every source file.
    //
    
    #import <Availability.h>
    
    #ifndef __IPHONE_5_0
    #warning "This project uses features only available in iOS SDK 5.0 and later."
    #endif
    
    #ifdef __cplusplus
    #include <opencv2/opencv.hpp>
    #endif
    
    #ifdef __OBJC__
        #import <UIKit/UIKit.h>
        #import <Foundation/Foundation.h>
    #endif
    

    这意味着您不会在此之前在应用程序的其他任何地方意外地包含一个苹果标题。

    【讨论】:

    • 这是准确的答案。
    【解决方案4】:

    我通过在 OpenCV 之前导入任何 Apple 标头解决了这个问题,如标头开头所述:

    #if defined(NO)
    #  warning Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers.
    #endif
    

    希望对您有所帮助。

    【讨论】:

    • 您的意思是在opencv 标头之后导入Apple 标头吗?它是include this header before any Apple headers,我尝试了#import &lt;opencv2/opencv.hpp&gt;,然后是#import &lt;UIKit/UIKit.h&gt;,它成功了。
    【解决方案5】:

    我遇到了类似的问题,我解决了直接编辑所涉及的 opencv-framework 文件(在您的情况下为 compensate.hpp)并从它们中评论 NO 枚举案例定义的定义。在这种情况下,文件是 blender.hpp,但 compensate.hpp 具有相同的结构

    希望对你有帮助

    【讨论】:

    • 这有点糟糕 ? 但是对于我的场景,OpenCV 是通过我们的库包含的,并且没有任何建议适用于使用它的应用程序,它节省了很多时间来启动和运行演示。由于这是一个内部尖峰,我现在可以忍受它。
    【解决方案6】:

    就我而言,我使用 openCV 创建了一个垂直图像拼接应用程序,错误如下图所示。它来自exposure_compensate.hppblenders.hpp。从错误描述来看,最上面的文件是../CVWrapper.mm,它在我的项目中,而不是openCV pod项目中。

    如上所述,C++ 和 Apple MACRO 之间存在一些冲突问题。我们应该将 C++ 头文件放在 Apple 头文件之上。

    首先,我尝试了一种来自互联网的解决方法,即“将NO 替换为NO_EXPOSURE_COMPENSATOR = 0”。这行得通,但它修改了 openCV 源代码,我不想这样做,因为我不会对 Pod 文件进行版本控制,那么如果其他人克隆我的 repo/项目,他们将需要对这些源代码进行相同的修改代码。

    然后,我按照 Xcode 中的错误消息,在我的 CVWrapper.mm 文件中进行了更改。之后,这两个错误就消失了。

    // Before change
    #import "CVWrapper.h"
    #import "UIImage+OpenCV.h"
    #import "stitching.h"
    #import "UIImage+Rotate.h"
    
    // After change
    #import "stitching.h"
    #import "CVWrapper.h"
    #import "UIImage+OpenCV.h"
    #import "UIImage+Rotate.h"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-24
      • 2014-09-09
      • 2020-08-26
      • 2012-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多