简体   繁体   English

错误:标识符“ img”未定义

[英]ERROR: identifier “img” is undefined

I'm beginner to openCV. 我是openCV的初学者。 I dowloaded opencv2.4.5 and visual studio express 2012 then i followed this link http://opencv-srf.blogspot.in/2013/05/installing-configuring-opencv-with-vs.html for setup everything in environment variable etc. Then i followed below link http://opencv-srf.blogspot.in/2013/06/load-display-image.html to create sample application. 我下载了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创建示例应用程序。 I included proper #include path. 我包括正确的#include路径。 But i'm getting error. 但是我出错了。

#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;
}

please do not use an absolute path for the includes, this is totally non-portable. 对于包括请不要使用绝对路径,这是完全不可移植。

it should look like this: 它应该看起来像这样:

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

also, to make this work, your "additional include folders" should point to "opencv/build/include" 同样,要使此工作正常进行,您的“其他包含文件夹”应指向“ opencv / build / include”

and avoid the old c-api headers, like cv.h, highgui.h, cxcore.h 并避免使用旧的c-api标头,例如cv.h,highgui.h,cxcore.h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM