Ask Your Question
0

What is problem with the following Opencv code?

asked 2013-04-23 16:08:12 -0600

hayden gravatar image

updated 2013-04-23 16:11:48 -0600

berak gravatar image

Hello Every body, i am trying to compile the following code which tries to print a 2 X2 Matrix M but I find error while compiling. Could anyone tell me what include file i am missing. Thanks.

/*********************/

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <math.h>

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

/****************************************************/
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-04-23 16:21:54 -0600

HD_Mouse gravatar image

Next time, it will help a lot to also copy and paste the error that you're getting. Otherwise, we have to copy your code to our computers and try running it ourselves, which we shouldn't have to deal with.

  1. You're using cout, which are members of the iostream library. You'll need to add iostream to the top.
  2. The opencv C++ headers are located under opencv2/. Remove cv.h, highgui.h and add opencv2/core/core.hpp instead. Your example doesn't use anything from highgui, but if you need it in the future, you can replace highgui.h with opencv2/highgui.hpp
  3. Make sure you link against opencv when compiling. Adding "-lopencv_core" will compile your code.
edit flag offensive delete link more

Comments

Sorry, I forgot to paste "#include < iostream> in the posting. It was already included in my coding. Next time I shall include the error too.

But I have installed OpenCV2.1.0 and there is no opencv2 directory and no core,hpp file. I can run some other opencv programs. But this one I can't. Please help me identify my problem. This is a very simple code.

hayden gravatar imagehayden ( 2013-04-23 17:12:22 -0600 )edit
1

answered 2013-04-23 16:19:50 -0600

berak gravatar image

#include<iostream> // for the printing

also, please:

#include <opencv2/core/core.hpp>

instead of :

#include <cv.h>
#include <cxcore.h>
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-04-23 16:08:12 -0600

Seen: 373 times

Last updated: Apr 23 '13