簡體   English   中英

無法在Visual Studio 2012項目中使用OpenCV

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM