Constants not found under Linux

asked 2013-05-28 14:57:26 -0500

Matheus Galvez gravatar image

updated 2013-05-28 15:06:01 -0500

Hi all,

I am trying to compile some simple OpenCV code for Linux Ubuntu. I have installed today the library under my Linux machine using this tutorial. After doing so successfully I tried to execute some code from the reference manual. The code is the following:

include <cstdlib>

include <iostream>

include <opencv2/opencv.hpp>

include <opencv2/opencv_modules.hpp>

using namespace cv; using namespace std;

int main(int argc, char** argv) {
VideoCapture cap(0); // open the default camera

if(!cap.isOpened()) // check if we succeeded
    return -1;
Mat edges;

    Mat frame;
    cap >> frame; // get a new frame from camera
    cvtColor(frame, edges, CV_BGR2GRAY);
    GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
    Canny(edges, edges, 0, 30, 3);
    imshow("edges", edges);
    if(waitKey(30) >= 0) break;

// the camera will be deinitialized automatically in VideoCapture destructor
return 0;


It can be found at page 326 of the manual.

For some reason I am getting the following error: main.cpp:28:32: error: ‘CV_BGR2GRAY’ was not declared in this scope

I tried to compile similar codes, using other constants prefixed by CV_ and the same happens all the time. Curiously I have brought this code from a Windows machine where I downloaded and installed OpenCV, configured Visual Studio 2010 to recognize it and compiled the code without problems. Can someone tell me what is happening?

Thank you all!

edit retag flag offensive close merge delete


if you actually downloaded from github master, yes they've done away with the CV_* prefix.

try COLOR_BGR2GRAY instead

berak gravatar imageberak ( 2013-05-28 15:29:20 -0500 )edit

I did different to solve it. I downloaded the file containing the latest version directly from the opencv website. I recompiled and installed again. Now it works properly.

Matheus Galvez gravatar imageMatheus Galvez ( 2013-05-28 15:40:00 -0500 )edit

ahh, ok. nice to hear, you solved it.

berak gravatar imageberak ( 2013-05-28 15:42:11 -0500 )edit

So does that mean I need to throw out the github version and start all over ???

Howard gravatar imageHoward ( 2013-05-28 15:43:12 -0500 )edit

@Howard Pautz:

valid complaint, imho ! ( though you deleted your initial comment)

start a new question with your findings, collect upvotes for that, attract some attention !

berak gravatar imageberak ( 2013-05-28 15:45:42 -0500 )edit

arggg :-| .... ok :))

Howard gravatar imageHoward ( 2013-05-28 15:46:52 -0500 )edit