C++ Windows 上的 Eclipse 上的 OpenCV
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13754348/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenCV on eclipse on windows
提问by Mohamed Wagdy Khorshid
I'm trying to install opencv on windows, here are my steps:
我正在尝试在 Windows 上安装 opencv,这是我的步骤:
- downloaded opencv 2.4.3 from website
- run the exe, extracted the folder in the same path
- opened eclipse (with MinGW previously set and configured)
- created new project XYZ
- added new folder "src"
- added new class "main.cpp"
added the following code:
hash include <cv.h>
hash include <highgui.h>using namespace cv; int main(int argc, char** argv) { Mat image; image = imread(argv[1], 1); if (argc != 2 || !image.data) { printf("No image data \n"); return -1; } namedWindow("Display Image", CV_WINDOW_AUTOSIZE); imshow("Display Image", image); waitKey(0); return 0; }
added the two paths
- "E:\Sources\opencv\build\include"
- "E:\Sources\opencv\build\include\opencv"
- got the compilation error
"Symbol 'cv' could not be resolved"
- 从网站下载了 opencv 2.4.3
- 运行exe,解压同路径下的文件夹
- 打开 eclipse(之前设置和配置了 MinGW)
- 创建了新项目 XYZ
- 添加了新文件夹“src”
- 添加了新类“main.cpp”
添加了以下代码:
散列包含 <cv.h>
散列包含 <highgui.h>using namespace cv; int main(int argc, char** argv) { Mat image; image = imread(argv[1], 1); if (argc != 2 || !image.data) { printf("No image data \n"); return -1; } namedWindow("Display Image", CV_WINDOW_AUTOSIZE); imshow("Display Image", image); waitKey(0); return 0; }
添加了两条路径
- "E:\Sources\opencv\build\include"
- "E:\Sources\opencv\build\include\opencv"
- 得到编译错误
"Symbol 'cv' could not be resolved"
Please advice if any step is missing
如有遗漏请指教
回答by lastjeef
you gonna need the latest stable version of openCV 2.4.3 .
你需要最新的稳定版 openCV 2.4.3 。
Eclipse Juno ! (Eclipse IDE for C/C++ Developers ) And MinGW - Minimalist GNU for Windows
日食朱诺!(适用于 C/C++ 开发人员的 Eclipse IDE)和 MinGW - 适用于 Windows 的极简主义 GNU
we will ignore x86/64 choice, since we gonna work with a 32 compiler / and 32 openCV build, even though the system is a 64 one !
我们将忽略 x86/64 选择,因为我们将使用 32 位编译器和 32 位 openCV 构建,即使系统是 64 位!
Step 1 : Download and Install
第 1 步:下载并安装
Eclipse
蚀
Download Eclipse from and decompress the archive . ( I assumed that you already have JRE on your computer , if not ! download and install it ) .
从 Eclipse 下载并解压缩存档。(我假设您的计算机上已经有 JRE,如果没有!下载并安装它)。
MinGW
明威
Download MinGW . the installer will lead you through the process ! you might have to add the bin directory to the path ! (Default path : C/MinGW/bin )
下载 MinGW 。安装程序将引导您完成整个过程!您可能必须将 bin 目录添加到路径中!(默认路径: C/MinGW/bin )
OpenCV
OpenCV
Download openCV exe from the link , extract the files (in the C:/ directory in this tutorial ) . Make sure you have the file structure below .
从链接下载 openCV exe,解压文件(在本教程的 C:/ 目录中)。确保您具有以下文件结构。
don't forget to add the bin directory => Path !
不要忘记添加 bin 目录 => Path !
As I mentioned earlier ! I'll use x86 build even if i have a 64 OS to avoid compiler problems and to keep this tutorial open to x86 OS users !
正如我之前提到的!即使我有 64 位操作系统,我也会使用 x86 构建以避免编译器问题并使本教程对 x86 操作系统用户开放!
Step 2 : Create and Configure
第 2 步:创建和配置
- Open the Eclipse IDE !
- Create a new C++ project : File > New > C++ Project
- Choose a Hello Word Project to have a pre structured one ! Don't forget to select the MinGW toolchains
- 打开 Eclipse IDE!
- 创建一个新的 C++ 项目:文件 > 新建 > C++ 项目
- 选择一个 Hello Word 项目以获得一个预先结构化的项目!不要忘记选择 MinGW 工具链
Click Finish and let's get to work !
单击完成,让我们开始工作吧!
Now that you have you first Hello word project ! replace the Code in the Soure file .cpp by the code below
现在您有了第一个 Hello word 项目!用下面的代码替换 Soure 文件 .cpp 中的代码
///////////////CODE///////////
///////////////代码///////////
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat im = imread(argc == 2 ? argv[1] : "lenna.png", 1);
if (im.empty())
{
cout << "Cannot open image!" << endl;
return -1;
}
imshow("image", im);
waitKey(0);
return 0;
}
///////////////CODE///////////
///////////////代码///////////
Obviously there are multiple errors on the code , yes ! we have to link the libraries !
显然代码中有多个错误,是的!我们必须链接库!
Now go to Properties >> C/C++ Build >> Settings on the Tool Setting tab >> GCC C++ Compiler >> Includes and include opencv path ! [opencvDir\build\include]
现在转到 Properties >> C/C++ Build >> Settings on the Tool Setting tab >> GCC C++ Compiler >> Includes and include opencv path ![opencvDir\build\include]
Now scroll to MinGW C++ Linker >> Libraries and add the Library search path [opencvDIR\build\x86\mingw\lib]
现在滚动到 MinGW C++ Linker >> Libraries 并添加库搜索路径 [opencvDIR\build\x86\mingw\lib]
in the Libraries part ! we add as much librarie as we need for the project ! here I added 4 libraries just for tutorial sake even if well need only the highgui one for our test code to work ! The libraries names can be found on the [opencvDIR\build\x86\mingw\lib] Example ! for libopencv_video243.dll.a wee add opencv_video243 in the linker !
在图书馆部分!我们为项目添加了尽可能多的库!在这里我添加了 4 个库只是为了教程,即使我们的测试代码只需要 highgui 一个!库名称可以在 [opencvDIR\build\x86\mingw\lib] 示例中找到!对于 libopencv_video243.dll.a wee 在链接器中添加 opencv_video243 !
click OK !
单击确定!
Now we can build our first project ! You figured that you have to add a picture to the project as implied in the source code "lenna.png" Use lenna for good luck
现在我们可以构建我们的第一个项目了!你认为你必须像源代码“lenna.png”中暗示的那样向项目添加图片使用lenna祝你好运
Build and Run the project ! If you see the beautiful lady :) Congrats :)
构建并运行项目!如果你看到美丽的女士:) 恭喜:)
have a look here for snapshots! opencveclipse-on-windows
看看这里的快照! opencveclipse-on-windows
回答by Tobias Hermann
cv.h is for the old C API. To use the Cpp API try the following:
cv.h 适用于旧的 C API。要使用 Cpp API,请尝试以下操作:
#include <opencv2/opencv.hpp>