0

I'm trying to build this code

#include "stdafx.h"
#include <iostream>

#include <math.h>
#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{   
    int pixel;

    Mat matC1_32S;

    return 0;
}

and I'm getting an error:

1>c:\test1\test1\test1.cpp(21): error C2065: 'Mat' : undeclared identifier
1>c:\test1\test1\test1.cpp(21): error C2146: syntax error : missing ';' before identifier 'matC1_32S'
1>c:\test1\test1\test1.cpp(21): error C2065: 'matC1_32S' : undeclared identifier

What additional includes should I have? or somethind else?

1
  • 1
    using namespace cv; or cv::Mat mat; Commented Mar 31, 2012 at 18:09

3 Answers 3

4

You aren't providing a namespace for Mat. This will work if you link to the OpenCV libraries when you compile:

#include "stdafx.h"
#include <iostream>

#include <math.h>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

using namespace std;
int _tmain(int argc, _TCHAR* argv[]) {
   int pixel;

   cv::Mat matC1_32S;

   return 0;
}

Or you can add using namespace cv; before _tmain so that you don't have to preface every appearance.

Also, you're overdoing the #include statements. You don't need the *_c.h files. (Maybe you added those when you were trying to figure out why Mat wasn't declared.)

Sign up to request clarification or add additional context in comments.

Comments

0

Thank you for help, but to make it work I actually had also to include the following

#ifdef _DEBUG 
  #pragma comment(lib, "opencv_core231d.lib") 
  #pragma comment(lib, "opencv_highgui231d.lib") 
  #pragma comment(lib, "opencv_imgproc231d")
  #pragma comment(lib, "opencv_objdetect231d.lib")

#else 
  #pragma comment(lib, "opencv_core231.lib") 
  #pragma comment(lib, "opencv_highgui231.lib") 
  #pragma comment(lib, "opencv_imgproc231.lib")
  #pragma comment(lib, "opencv_objdetect231.lib")

#endif 

I understand why I need 'using namespace cv, but why do I need this stuff with pragma, despite that I provided libraries path in the project properties. ('m using VisualStudio 10

1 Comment

The errors you showed are compilation errors, adding 'using namespace cv' would fix them (although I would suggest 'cv::Mat' instead of 'using namespace cv'). Missing '#pragma comment(lib, "opencv_core231.lib")' is a different problem, you provided paths to the linker, but the linker still have no idea which library to link to. You need to tell it explicitly. You can also do this by adding the libraries into project Configuration Properties -> Linker -> Input -> Additional Dependencies in VisualStudio 10.
0

you have to go to properties >> C/C++ >> Avanced >> Compile As and choose Compile as C++ code /TP I did it. It works.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.