在iOS下使用Stitcher时出现OpenCV编译器错误

Chr*_*ris 7 compiler-construction opencv ios

每当我尝试在iOS中使用OpenCV Stitcher类并且我包含stitcher-header(#include)时,我最终会在exposure_compensate.hpp中出现编译错误"Expected'{'".显然行enum {NO,GAIN,GAIN_BLOCKS}; 造成某种错误.

我是openCV的新手,但使用filter2d()等其他函数按预期工作.我该如何解决这个问题?

sup*_*org 11

尝试

#import <opencv2/opencv.hpp>
Run Code Online (Sandbox Code Playgroud)

然后

#import <UIKit/UIKit.h>
Run Code Online (Sandbox Code Playgroud)


Joe*_*ply 5

在您的项目中,创建一个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
Run Code Online (Sandbox Code Playgroud)


G. *_*ühr 2

我通过在 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
Run Code Online (Sandbox Code Playgroud)

希望有帮助。