我正在使用OpenCV 2.3.1建立一台新机器。该机器是Windows 7机器,我按照OpenCV网站提供的安装说明(使用CMake和MinGW构建)。
这是我的代码:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main() {
char var;
cv::Mat img;
img = cv::imread("C:/test/img.jpg");
cv::namedWindow("Image");
cv::imshow("Image", img);
std::cin >> var;
return 1;
}
这是我的make命令:
g++ -o main main.cpp -lopencv_core -lopencv_imgproc -lopencv_calib3d -lopencv_video -lopencv_features2d -lopencv_ml -lopencv_highgui -lopencv_objdetect -lopencv_contrib -lopencv_legacy
这是我的路径:
C:\OpenCV-2.3.1\install\bin;C:\OpenCV-2.3.1\install\include;C:\QtSDK\QtCreator\bin;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\CMake 2.8\bin;C:\QtSDK\mingw\bin;
这是我的错误:
main.cpp:2:33: error: opencv2/core/core.hpp: No such file or directory
main.cpp:3:39: error: opencv2/highgui/highgui.hpp: No such file or directory
main.cpp: In function 'int main()':
main.cpp:8: error: 'cv' has not been declared
main.cpp:8: error: expected ';' before 'img'
main.cpp:9: error: 'img' was not declared in this scope
main.cpp:9: error: 'cv' has not been declared
main.cpp:10: error: 'cv' has not been declared
main.cpp:11: error: 'cv' has not been declared
这没有意义。为什么不编译?为什么找不到opencv2 / core / core.hpp?
答案 0 :(得分:2)
g++
不会考虑%PATH%
(在Unix上为$PATH
。
将以下内容添加到编译命令:-IC:\OpenCV-2.3.1\install\include
:
g++ -IC:\OpenCV-2.3.1\install\include -o main main.cpp -lopencv_core ...
答案 1 :(得分:0)
您没有包含正确的OpenCV目录。
我在C:\OpenCV2.3
中安装了以前版本的OpenCV,这些是我为编译器添加标题而添加的路径:
C:\OpenCV2.3\build\include\opencv
C:\OpenCV2.3\build\include\opencv2
C:\OpenCV2.3\build\include
传统上, g ++ 会使用-I
标记来获取标题目录,您似乎根本没有使用它。
答案 2 :(得分:0)
在unix上,如os
g++ filename.cpp -o exec `pkg-config opencv cvblob --libs --cflags`
(如果要检查blob,则可选择cvblob)