A basic question on OpenCV on "#include <opencv2/core/core.hpp>",

asked 2013-04-24 15:57:00 -0500

hayden gravatar image

updated 2013-04-25 01:29:39 -0500

berak gravatar image

Hello every body, last time I wrote about getting error in printing a matrix in OpenCV. Iwas suggested to include: #include <opencv2/core/core.hpp> But I have installed OpenCV2.1.0 and I have compiled with visual studio 2010 and there is no opencv2 directory and no core.hpp file. In that case how to compile the following program as if I include

#include <opencv2/core/core.hpp>

it does not work.


#include <iostream>

#include <opencv2/core/core.hpp>

using namespace cv;

using namespace std;

int main(){  

    Mat M(2,2, CV_8UC3, Scalar(0,0,255));

    cout << "M = " << endl << " " << M << endl << endl;

    return 0;


it shows  the following error:
fatal error C1083: Cannot open include file: 'opencv2/core/core.hpp': No such file or directory
But using  #include <cv.h>, #include <cxcore.h>, #include <highgui.h>, I can compile the follwong program:


#include <cv.h>

#include <highgui.h>

#include <math.h>

using namespace cv;

int main(int argc, char** argv)


    Mat img, gray;

    img=imread("2.jpg", CV_LOAD_IMAGE_GRAYSCALE);

    // smooth it, otherwise a lot of false circles may be detected

    GaussianBlur( img, img, Size(9, 9), 2, 2 );

    vector<Vec3f> circles;

    HoughCircles(img, circles, CV_HOUGH_GRADIENT, 2, img.rows/4, 200, 100 );

    for( size_t i = 0; i < circles.size(); i++ ){

         Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));

         int radius = cvRound(circles[i][2]);

         circle( img, center, 3, Scalar(0,255,0), -1, 8, 0 );

         circle( img, center, radius, Scalar(0,0,255), 3, 8, 0 );

    namedWindow( "circles", 1 );

    imshow( "circles", img );


    return 0;

/******************/ Please provide me some suggestion. enter code here`

edit retag flag offensive close merge delete


Did you check your OpenCV folder ? I had some troubles when building OpenCV (but it's 2.4.9) on w7 64bits with VS2010 : my opencv\build\include folder was empty.

The "normal" structure is : opencv\build\include\opencv <== here you have C headers opencv\build\include\opencv2 <== here you have C++ headers

It can also be in project properties > c/c++ > other include directories (not sure for the names, my vs is in french...). is it opencv\build\include\opencv or opencv\build\include ?

Rogeeeer gravatar imageRogeeeer ( 2013-04-25 02:54:57 -0500 )edit

Basically do not use openCV 2.1 but download the 2.4.5 edition. There are tons of bugs fixed and the source code changed quite alot. If the error still persists then, people do get a reference on the fact if it is still a bug.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-25 04:26:27 -0500 )edit

Also be sure to add the include directories into your general C/C++ project settings. If not, the headers will indeed never be found :)

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-25 04:27:21 -0500 )edit

I would like to build opencv from source, please tell me which version I should use.

hayden gravatar imagehayden ( 2013-04-25 11:53:16 -0500 )edit

the latest stable version 2.4.5

StevenPuttemans gravatar imageStevenPuttemans ( 2013-04-25 12:10:37 -0500 )edit