我如何正确地将OpenCV库链接到Windows上的Eclipse? [英] How can I correctly link OpenCV libraries to Eclipse on Windows?
问题描述
#include< opencv2 / core / core.hpp>
#include< opencv2 / highgui / highgui.hpp>
#include< iostream>
使用namespace cv;
使用namespace std;
int main(int argc,char ** argv)
{
if(argc!= 2)
{
cout <<<用法:display_image ImageToLoadAndDisplay<< ENDL;
返回-1;
}
Mat图像;
image = imread(argv [1],CV_LOAD_IMAGE_COLOR); //读取文件
if(!image.data)//检查无效输入
{
cout<< 无法打开或找到图片<< std :: endl;
返回-1;
}
namedWindow(Display window,WINDOW_AUTOSIZE); //创建一个窗口进行显示。
imshow(显示窗口,图像); //在里面显示我们的图像。
waitKey(0); //等待窗口中的按键
返回0;
}
到目前为止我所做的一切:
- 安装了MinGW(在E:\NVPACK\MinGW中),并将其bin文件路径添加到我的环境变量中。
- 在E:\opencv上安装OpenCV 2.4.12。在安装的文件夹里面是build和sources文件夹。 使用MinGW GCC Toolchain创建了一个新的Eclipse C ++项目。 在工具设置(工程属性 - > C / C ++构建 - >设置)中,我将OpenCV库包含在GCC C ++编译器中作为E :\opencv\build\include
-
在MinGW C ++链接器中添加的工具设置中,所有库(例如opencv_core2412,opencv_highgui2412,opencv_imgproc2412 ),并将库搜索路径设置为E:\\\\\\\\\\\\\\\\\\\' PE Windows Parser。
构建项目所有的OpenCV函数都会得到未定义的引用错误,例如:
对`cv :: imread(std :: string const&; int)'的未定义引用main.cpp第17行C / C ++问题
未定义引用`cv :: _ InputArray :: _ InputArray(cv :: Mat const&)'main.cpp line 26 C / C ++ Problem
奇怪的是,声明Mat图不会给出错误,并将鼠标悬停在它上面c或者直接显示OpenCV的Mat文档。
谷歌搜索问题我发现由于某种原因,我可能需要使用CMake来构建我自己的库文件(步骤5中使用的文件)。所以在安装CMake gui后,我使用E:\opencv\sources作为源目录,并创建了一个新的目录E:\\\\\\\\\\\\\\\\\\'作为我的编译目录。我使用Eclipse CDT4 -MinGW Makefiles生成器来配置文件。在按下Configure之后,我将为我的g ++编译器(类似于我的gcc编译器)收到以下错误:
CMake错误CMakeLists.txt:71(project):
CMAKE_CXX_COMPILER:
E:/ NVPACK / MinGW / bin / mingw32-g ++
不是完整路径到现有的编译器工具。
通过将环境
变量CXX或CMake缓存项CMAKE_CXX_COMPILER设置为完整路径
给编译器或编译器,告诉CMake在哪里可以找到编译器名称,如果它在PATH中。
然而编译器识别出:CXX编译器标识符是GNU 4.8.1和C编译器标识是GNU 4.8.1
任何有关如何在Windows 7上的Eclipse Mars中正确设置OpenCV 2.4.12库的帮助将非常感谢! / p>
嗯,我希望这已经够详细了!首先,一大杯咖啡会有帮助!
让我们开始吧:
要求:
b- 从 github回购下载OpenCV源代码(将它解压到一个我们将命名为
opencv_src_folder
的文件夹) - 下载并安装MinGW系统路径)
- 下载并安装 CMake
- 将src文件夹设置为
opencv_src_folder
- 将build文件夹设置为
opencv_src_folder / Mingw_build /
- 点击
configure
然后选择Eclipse CDT4 - MinGW MakeFile
然后选择下一步。
- 如果配置成功,点击
/ code>。
- 如果配置成功,点击
-
打开命令行(Windows + R)
- $
cd opencv_src_folder / Mingw_build /
- $
mingw32- make
:
这将使用MinGW创建openCV,所以请等待它完成! - 现在,让我们安装$
mingw32 -make install
这将在opencv_src_folder / Mingw_build / install / 中安装cmake
- $
-
将
opencv_src_folder / Mingw_build / install / bin /
添加到您的系统路径&
-
Eclipse配置:
- 转到Eclipse CDT IDE,使用示例OpenCV代码创建一个C ++程序。
- 转到Project> Properties> C / C ++ Build> Settings> GCC C ++ Compiler>包含并添加源OpenCV文件夹打开项目>属性> C / C ++编译>设置> MinGW C ++链接器>库,并添加到库(-l)中。 )分别:(不要忘记更改245到哪个号码,他们使用的lib文件)
opencv_calib3d245 opencv_contrib245 opencv_core245 opencv_features2d245 opencv_flann245 opencv_gpu245 opencv_highgui245 opencv_imgproc245 opencv_legacy245 opencv_ml245 opencv_nonfree245 opencv_objdetect245
opencv_photo245 opencv_stitching245 opencv_video245 opencv_videostab245
(-L)。 - 转到Eclipse CDT IDE,使用示例OpenCV代码创建一个C ++程序。
步骤: >打开CMake-gui
测试: 您可以使用以下代码作为测试: 最后建立您的项目! 希望有所帮助! For the last couple of hours I have been trying to get a basic OpenCV program to work in my Eclipse Mars IDE. The program consists of the following main.cpp: What I have done up till now: Installed OpenCV 2.4.12 at E:\opencv. Inside the installed folder are the "build" and "sources" folder. Made a new Eclipse C++ project with the MinGW GCC Toolchain. Inside the Tool Settings (Project Properties --> C/C++ Build --> Settings) I included the OpenCV library in the GCC C++ Compiler as "E:\opencv\build\include" Inside the Tool Settings I added in the MinGW C++ Linker all the libraries (i.e. opencv_core2412, opencv_highgui2412, opencv_imgproc2412) and set the Library search path to "E:\opencv\build\x86\vc12\lib" Set my Binary parser to PE Windows Parser. Building the project all the OpenCV functions get undefined references errors, such as: Weird enough, declaring Mat image does not give an error and holding my mouse over it correctly displays the OpenCV's Mat documentation. Googling the problem I found that for some reason I might need to use CMake to build my own library files (the ones used in step 5). So after installing CMake gui, I used E:\opencv\sources as the source directory and made a new directory E:\opencv\MinGW as my build directory. I used "Eclipse CDT4 -MinGW Makefiles" generator to Configure the files. After pressing Configure, I will receive the following error for my g++ compiler (a similar one for my gcc compiler): The compilers are however identified: "The CXX compiler identification is GNU 4.8.1" and "The C compiler identification is GNU 4.8.1" Any help on how to correctly set up the OpenCV 2.4.12 libraries in Eclipse Mars on Windows 7 would be very much appreciated! Well, I hope this is detailed enough ! First of all, a big cup of coffee will help ! Let's get started : Requirements : Steps : Open CMake-gui Open a command line (Windows + R) Add Eclipse Configuration : Go to Project > Properties > C/C++ Build > Settings > MinGW C++ Linker > Libraries, and add to the Libraries (-l) separately : (Don't forget to change the 245 to whichever number they use for the lib files)
opencv_calib3d245 opencv_contrib245 opencv_core245 opencv_features2d245 opencv_flann245 opencv_gpu245 opencv_highgui245 opencv_imgproc245 opencv_legacy245 opencv_ml245 opencv_nonfree245 opencv_objdetect245
opencv_photo245 opencv_stitching245 opencv_video245 opencv_videostab245 Add the built OpenCV library folder, Testing : you can use the following code as a test : And last build your project ! Hope that helps ! 这篇关于我如何正确地将OpenCV库链接到Windows上的Eclipse?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
#include< opencv2 / core / core.hpp>
#include< opencv2 / highgui / highgui.hpp>
#include< iostream>
使用namespace cv;
使用namespace std;
int main(int argc,char ** argv)
{
if(argc!= 2)
{
cout <<<用法:display_image ImageToLoadAndDisplay<< ENDL;
返回-1;
}
Mat图像;
image = imread(argv [1],CV_LOAD_IMAGE_COLOR); //读取文件
if(!image.data)//检查无效输入
{
cout<< 无法打开或找到图片<< std :: endl;
返回-1;
}
namedWindow(Display window,WINDOW_AUTOSIZE); //创建一个窗口进行显示。
imshow(显示窗口,图像); //在里面显示我们的图像。
waitKey(0); //等待窗口中的按键
返回0;
}
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
undefined reference to `cv::imread(std::string const&, int)' main.cpp line 17 C/C++ Problem
undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)' main.cpp line 26 C/C++ Problem
CMake Error at CMakeLists.txt:71 (project):
The CMAKE_CXX_COMPILER:
E:/NVPACK/MinGW/bin/mingw32-g++
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
opencv_src_folder
)
opencv_src_folder
opencv_src_folder/Mingw_build/
configure
and choose Eclipse CDT4 - MinGW MakeFile
then next.generate
.
cd opencv_src_folder/Mingw_build/
mingw32-make
:
this will make openCV using MinGW, so wait until it's finished !mingw32-make install
this will install cmake in opencv_src_folder/Mingw_build/install/opencv_src_folder/Mingw_build/install/bin/
to your system path & restart session.
opencv_src_folder/Mingw_build/install/lib
to Library search path (-L).#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}