如何在Cocoa应用程序中包含OpenCV? [英] How to include OpenCV in Cocoa Application?

查看:123
本文介绍了如何在Cocoa应用程序中包含OpenCV?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用'命令行工具'c ++ stdc ++模板创建一个xCode项目时,我能够包含和编译opencv头文件并运行一些代码。

when I create an xCode project with the 'Command Line Tool' c++ stdc++ template, i am able to include and compile opencv headers and run some code.

但我想在Cocoa Application环境中使用OpenCV。当使用该模板创建时,当我在main.mm中包含OpenCV头文件时,我得到编译错误。 (我已经改变main.m到main.mm,'// NSApplicationMain(argc,(const char **)argv);'注释掉了)

But i want to use OpenCV in a 'Cocoa Application' context. When created with that template, i got compile errors when I include the OpenCV headers in main.mm. (I already changed main.m to main.mm, the '//NSApplicationMain(argc, (const char **) argv);' is commented out)

这些错误是:语句表达式只允许在函数内部

One of those errors is: "Statement-expressions are allowed only inside functions"

我想它的某种编译器版本错误,但是当我比较项目构建设置找到差异。

I suppose its some kind of compiler version error, but when i compare the project build settings i cant find differences.

你有什么想法/专业知识吗?

Do you have any ideas/expertise?

推荐答案

我遇到了同样的问题,我花了2天做严重的系统跟踪和预期,解决方案很简单,

I ran into the same problem, I spent 2 days doing serious system tracing and as expected, the solution was so simple that an 8-year-old could have found it more quickly than I did.

准备好了吗?

在.mm文件中,你想使用OpenCV,你需要在你的 #includeopencv2 / opencv.hpp之前的任何其他包含。而已!

In the .mm file where you want to use OpenCV, you need to do your #include "opencv2/opencv.hpp" BEFORE any other includes. That's it! Just move it up a line and watch your problem magically disappear faster than that rug that really tied the room together.

这是为了OpenCV 2.2的方式,因此新的包含文件。如果你的XCode项目使用一个前缀头文件(查看其他来源的YourProjectName_Prefix.pch文件),那么你需要把你的 #includeopencv2 / opencv.hpp ,而不是在任何其他文件。

This is for OpenCV 2.2 by the way, hence the new include file. Also if your XCode project uses a prefix header file (look in "Other Sources" for a "YourProjectName_Prefix.pch" file), then you'll need to put your #include "opencv2/opencv.hpp" there instead of in any other file.

这篇关于如何在Cocoa应用程序中包含OpenCV?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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