[英]Unable to use OpenCV in Visual Studio 2012 project
我正在使用MS Visual Studio 2012和OpenCV 3.1。 我想编译这段代码:
#include <opencv2/opencv.hpp>
using namespace cv;
int main(){
//Generate matrix to store image
Mat image;
//initialize capture
VideoCapture cap;
cap.open(0);
//Create window to show image
namedWindow("window", 1);
while (1){
//copy webcam stream to image
cap >> image;
//print image to screen
imshow("window", image);
//delay 33ms
waitKey(33);
}
}
但是,我得到这些错误:
Error 1 error C2065: 'videoCapture' : undeclared identifier C:\Users\patha\documents\visual studio 2012\Projects\video\video\video.cpp 8 1 video
Error 2 error C2146: syntax error : missing ';' before identifier 'cap' C:\Users\patha\documents\visual studio 2012\Projects\video\video\video.cpp 8 1 video
Error 3 error C2065: 'cap' : undeclared identifier C:\Users\patha\documents\visual studio 2012\Projects\video\video\video.cpp 8 1 video
Error 4 error C2065: 'cap' : undeclared identifier C:\Users\patha\documents\visual studio 2012\Projects\video\video\video.cpp 9 1 video
Error 5 error C2228: left of '.open' must have class/struct/union C:\Users\patha\documents\visual studio 2012\Projects\video\video\video.cpp 9 1 video
Error 6 error C2065: 'cap' : undeclared identifier C:\Users\patha\documents\visual studio 2012\Projects\video\video\video.cpp 14 1 video
Error 7 error C3861: 'waitkey': identifier not found C:\Users\patha\documents\visual studio 2012\Projects\video\video\video.cpp 18 1 video
8 IntelliSense: identifier "videoCapture" is undefined c:\Users\patha\Documents\Visual Studio 2012\Projects\video\video\video.cpp 8 6 video
9 IntelliSense: identifier "waitkey" is undefined c:\Users\patha\Documents\Visual Studio 2012\Projects\video\video\video.cpp 18 6 video
要在VS中使用OpenCV,您需要将其包含路径(即-path-to-OpenCV-3.1.0\\build\\include
)添加到项目的“ 包含目录”中 。
阅读这篇文章以获取更多信息。
该代码是完美的,并且可以在我的机器上运行。 问题可能出在编译无法识别OpenCV库。 因此,您需要正确设置它, 该视频将为您提供帮助。
看起来OpenCV 3.1.0没有vc11库。 它只有vc12和vc14。 让您选择安装Visual Studio 2013或更高版本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.