C++ OpenCV hello world没有像它应该的那样编译
我正在用OpenCV 2.3.1安装一台新机器。这台机器是一台Windows7机器,我遵循OpenCV网站(使用CMake和MinGW构建)给出的安装说明 这是我的密码:C++ OpenCV hello world没有像它应该的那样编译,c++,opencv,computer-vision,C++,Opencv,Computer Vision,我正在用OpenCV 2.3.1安装一台新机器。这台机器是一台Windows7机器,我遵循OpenCV网站(使用CMake和MinGW构建)给出的安装说明 这是我的密码: #include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> int main() { char var; cv::Mat img; img =
#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;
}
以下是我的路径:
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在查找包含文件时,P><代码> G++< /COD>不考虑<代码> %PATH %(<代码> $PATH < /Cord>)。 将以下内容添加到编译命令中:
-IC:\OpenCV-2.3.1\install\include
:
g++ -IC:\OpenCV-2.3.1\install\include -o main main.cpp -lopencv_core ...
您没有包括正确的OpenCV目录 我在
C:\OpenCV2.3
中安装了早期版本的OpenCV,以下是我必须添加的路径,以便我的编译器查找标题:
C:\OpenCV2.3\build\include\opencv
C:\OpenCV2.3\build\include\opencv2
C:\OpenCV2.3\build\include
传统上,g++使用带有-I
标志的标题目录,而您似乎根本没有使用该标志。在类unix操作系统上
g++ filename.cpp -o exec `pkg-config opencv cvblob --libs --cflags`
(如果您正在检查blob,则cvblob是可选的)您可以发布一个指向您遵循的说明的链接吗?这是QT creator未正确编译的更多疑难解答。。。同样的问题?
g++ filename.cpp -o exec `pkg-config opencv cvblob --libs --cflags`