Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV2, c++ - cv::CV_8UC4 expected unqualified-id

Tags:

c++

opencv

:::c++
#include <opencv2/opencv.hpp>
#include <stdio.h>
int main(int argc, char** argv){
    int x = cv::CV_8UC4;
    std::cout << x;
    return 0;
}

I'm actually trying to create a cv::Mat(r,c,cv::CV_8UC4,ptr,0) but to identify the error, I created the above. Compiling with g++ or clang++ both give this error (clang version):

test.cpp:4:17: error: expected unqualified-id
int x = cv::CV_8UC4;
            ^
/usr/include/opencv2/core/types_c.h:584:17: note: expanded from macro 'CV_8UC4'
#define CV_8UC4 CV_MAKETYPE(CV_8U,4)
                ^
/usr/include/opencv2/core/types_c.h:578:32: note: expanded from macro 'CV_MAKETYPE'
#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
                               ^
/usr/include/opencv2/core/types_c.h:576:33: note: expanded from macro 'CV_MAT_DEPTH'
#define CV_MAT_DEPTH(flags)     ((flags) & CV_MAT_DEPTH_MASK)

Googling the error was of little help.

like image 644
justinzane Avatar asked Oct 28 '13 22:10

justinzane


1 Answers

It's not cv::CV_8UC4 it's just CV_8UC4

For historical reasons and interop with the C version the macros aren't in the cv:: namespace

like image 145
Martin Beckett Avatar answered Oct 23 '22 10:10

Martin Beckett