2014-04-21 150 views
0

我是初學者openCV。我dowloaded opencv2.4.5和visual studio express 2012然後我跟着這個鏈接http://opencv-srf.blogspot.in/2013/05/installing-configuring-opencv-with-vs.html設置一切環境變量等然後我下面鏈接http://opencv-srf.blogspot.in/2013/06/load-display-image.html創建示例應用程序。我包含了正確的#include路徑。但我得到錯誤。錯誤:標識符「img」未定義

#include "stdafx.h" 

#include <C:\opencv\build\include\opencv\cv.h> 
#include <C:\opencv\build\include\opencv\cxcore.h> 
#include <C:\opencv\build\include\opencv\highgui.h> 

#include "C:\opencv\build\include\opencv2\highgui\highgui.hpp" 
#include <iostream> 

using namespace cv; 
using namespace std; 

int main(int argc, const char** argv) 
{ 
    Mat img = imread("MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img' 

    if (img.empty()) //check whether the image is loaded or not 
    { 
      cout << "Error : Image cannot be loaded..!!" << endl; 
      //system("pause"); //wait for a key press 
      return -1; 
    } 

    namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow" 
    imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window 

    waitKey(0); //wait infinite time for a keypress 

    destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow" 

    return 0; 
} 
+0

哪一行導致錯誤? –

回答

1

請不要使用絕對路徑,包括,這是完全不可移植。

它應該是這樣的:

// the usual suspects: 
#include "opencv2\core\core.hpp"  // Mat is defined here. 
#include "opencv2\imgproc\imgproc.hpp" 
#include "opencv2\highgui\highgui.hpp" 

此外,爲了使這項工作,你的「附加包含文件夾」應指向「的OpenCV /建設/包括」

,避免老C- api頭文件,如cv.h,highgui.h,cxcore.h

+0

我得到不能開源文件「opencv2 \ core \ core.hpp」所有這些包括行..在「額外的包括文件夾」我用下面行$(OPENCV_DIR)\包括 – user3496826

+0

所以去檢查$(OPENCV_DIR)指向正確的地方。甚至可能是錯誤的。該文件應該在「opencv/build/include」 – berak

+0

我不明白。在哪裏檢查? – user3496826

相關問題