我对OpenCV有点陌生,我在Java OpenCV中做了一些东西,但受这个库的限制,我很难进入C/C++!
我已经成功地构建和运行了C OpenCV项目,但看到大多数教程都在C++版本上运行,我正在尝试制作一个简单的"HelloCV":
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("c:/lenna.png", CV_LOAD_IMAGE_COLOR);
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);
waitKey(0);
return 0;
}
我总是收到以下错误:
../src/mainCPP.cpp:12: undefined reference to `cv::imread(std::string const&, int)'
../src/mainCPP.cpp:14: undefined reference to `cv::namedWindow(std::string const&, int)'
../src/mainCPP.cpp:15: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
../src/mainCPP.cpp:15: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
../src/mainCPP.cpp:17: undefined reference to `cv::waitKey(int)'
srcmaincpp.o: In function `ZN2cv3MatD1Ev':
C:/OpenCV_2.4.9/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
srcmaincpp.o: In function `ZN2cv3Mat7releaseEv':
C:/OpenCV_2.4.9/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
我已经遵循了大约4-5个安装教程,但我只成功地破坏了我的项目!
我的"工作"设置:
- C/C++内部版本->GCC C++编译器->包含->包含路径(-I):包含文件夹的路径("C:\OpenCV_2.4.9\OpenCV\Build\Include")
- C/C++构建->GCC C++链接器->库->库搜索路径(-L)->"C:\OpenCV_2.4.9\OpenCV\Build\x86\vc11\lib",我知道我已经将路径放在x86而不是x64,因为lib错误类似:"不兼容的系统架构"
- C/C++构建->GCC C++链接器->库->库(-l):opencv_core249、opencv_imgproc249和highgui249(我测试过包括所有库,但都是一样的)
我添加了环境变量:C:\OpenCV_2.4.9\OpenCV\build\x86\vc11\bin(它不是只适用于M$Visual Studio吗?!)
看起来openCV没有正确安装。尝试使用Chocolatey,它可以在windows上干净地安装最新版本的OpenCV。