Question

I used javaCV for my android application: When I'm trying to covert an image into a grayscale image, eclipse cannot find the constant CV_BGR2GRAY.

can anyone help me out? Thank you.

  cvCvtColor(originalImage,grayImage,CV_BGR2GRAY);

Also, eclipse cannot find the constant for CASCADE_FILE in

 CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(cvLoad(CASCADE_FILE));
Was it helpful?

Solution

I am using OpenCV in C/C++ version, but the concepts I'm pointing are still valid.

OpenCV constant CV_BGR2GRAY belongs to an enumerative type defined in the source file types_c.h:

/* Constants for color conversion */

enum {

CV_BGR2BGRA    =0,
CV_RGB2RGBA    =CV_BGR2BGRA,

CV_BGRA2BGR    =1,
CV_RGBA2RGB    =CV_BGRA2BGR,

CV_BGR2RGBA    =2,
CV_RGB2BGRA    =CV_BGR2RGBA,

CV_RGBA2BGR    =3,
CV_BGRA2RGB    =CV_RGBA2BGR,

CV_BGR2RGB     =4,
CV_RGB2BGR     =CV_BGR2RGB,

CV_BGRA2RGBA   =5,
CV_RGBA2BGRA   =CV_BGRA2RGBA,

CV_BGR2GRAY    =6,
CV_RGB2GRAY    =7,
CV_GRAY2BGR    =8,
CV_GRAY2RGB    =CV_GRAY2BGR,
CV_GRAY2BGRA   =9,
CV_GRAY2RGBA   =CV_GRAY2BGRA,
CV_BGRA2GRAY   =10,
CV_RGBA2GRAY   =11,

CV_BGR2BGR565  =12,
CV_RGB2BGR565  =13,
CV_BGR5652BGR  =14,
CV_BGR5652RGB  =15,
CV_BGRA2BGR565 =16,
CV_RGBA2BGR565 =17,
CV_BGR5652BGRA =18,
CV_BGR5652RGBA =19,

CV_GRAY2BGR565 =20,
CV_BGR5652GRAY =21,

CV_BGR2BGR555  =22,
CV_RGB2BGR555  =23,
CV_BGR5552BGR  =24,
CV_BGR5552RGB  =25,
CV_BGRA2BGR555 =26,
CV_RGBA2BGR555 =27,
CV_BGR5552BGRA =28,
CV_BGR5552RGBA =29,

CV_GRAY2BGR555 =30,
CV_BGR5552GRAY =31,

CV_BGR2XYZ     =32,
CV_RGB2XYZ     =33,
CV_XYZ2BGR     =34,
CV_XYZ2RGB     =35,

CV_BGR2YCrCb   =36,
CV_RGB2YCrCb   =37,
CV_YCrCb2BGR   =38,
CV_YCrCb2RGB   =39,

CV_BGR2HSV     =40,
CV_RGB2HSV     =41,

CV_BGR2Lab     =44,
CV_RGB2Lab     =45,

CV_BayerBG2BGR =46,
CV_BayerGB2BGR =47,
CV_BayerRG2BGR =48,
CV_BayerGR2BGR =49,

CV_BayerBG2RGB =CV_BayerRG2BGR,
CV_BayerGB2RGB =CV_BayerGR2BGR,
CV_BayerRG2RGB =CV_BayerBG2BGR,
CV_BayerGR2RGB =CV_BayerGB2BGR,

CV_BGR2Luv     =50,
CV_RGB2Luv     =51,
CV_BGR2HLS     =52,
CV_RGB2HLS     =53,

CV_HSV2BGR     =54,
CV_HSV2RGB     =55,

CV_Lab2BGR     =56,
CV_Lab2RGB     =57,
CV_Luv2BGR     =58,
CV_Luv2RGB     =59,
CV_HLS2BGR     =60,
CV_HLS2RGB     =61,

CV_BayerBG2BGR_VNG =62,
CV_BayerGB2BGR_VNG =63,
CV_BayerRG2BGR_VNG =64,
CV_BayerGR2BGR_VNG =65,

CV_BayerBG2RGB_VNG =CV_BayerRG2BGR_VNG,
CV_BayerGB2RGB_VNG =CV_BayerGR2BGR_VNG,
CV_BayerRG2RGB_VNG =CV_BayerBG2BGR_VNG,
CV_BayerGR2RGB_VNG =CV_BayerGB2BGR_VNG,

CV_BGR2HSV_FULL = 66,
CV_RGB2HSV_FULL = 67,
CV_BGR2HLS_FULL = 68,
CV_RGB2HLS_FULL = 69,

CV_HSV2BGR_FULL = 70,
CV_HSV2RGB_FULL = 71,
CV_HLS2BGR_FULL = 72,
CV_HLS2RGB_FULL = 73,

CV_LBGR2Lab     = 74,
CV_LRGB2Lab     = 75,
CV_LBGR2Luv     = 76,
CV_LRGB2Luv     = 77,

CV_Lab2LBGR     = 78,
CV_Lab2LRGB     = 79,
CV_Luv2LBGR     = 80,
CV_Luv2LRGB     = 81,

CV_BGR2YUV      = 82,
CV_RGB2YUV      = 83,
CV_YUV2BGR      = 84,
CV_YUV2RGB      = 85,

CV_BayerBG2GRAY = 86,
CV_BayerGB2GRAY = 87,
CV_BayerRG2GRAY = 88,
CV_BayerGR2GRAY = 89,

CV_YUV420i2RGB  = 90,
CV_YUV420i2BGR  = 91,
CV_YUV420sp2RGB = 92,
CV_YUV420sp2BGR = 93,

CV_COLORCVT_MAX  =100 };

First of all check if types_c.h header file is correctly included in library's source files: on my UNIX system I've found it at path /usr/local/include/opencv2/imgproc/types_c.h.

If it is there it might simply be a problem in your compilation options: be sure you are correctly including and linking all library files.

In my case I specified library's search path with the following:

  • -L/usr/local/lib
  • -lopencv_core -lopencv_highgui

and obviously included libraries for the compiler:

  • -I/usr/local/include/opencv

If it still isn't working just try to call function cv::cvCvtColor() specifying value 6 as last input parameter (it's the int corresponding to the enumerative type constant CV_BGR2GRAY):

cvCvtColor(originalImage,grayImage, 6 );

Regarding your second error I don't know what to say, it may be due to the same problems I've stated before.

Check if resolving the first one also fixes the second.

AND PLEASE PUT MORE EFFORT IN YOUR QUESTIONS!

OTHER TIPS

I think this constant is: org.opencv.imgproc.ImgProc.COLOR_BGR2GRAY

Why it's not CV_BGR2GRAY is an artefact of the automatic conversion of the C interface to Java.

(And the question is perfectly clear and relevant, if you know about OpenCV Java. If you don't, why post 100 lines about the C/C++ interface and moan at the questioner).

here “import org.opencv.imgproc.Imgproc”

Please import this static parameter in your top of ActivityClass File.

import static org.bytedeco.javacpp.opencv_imgproc.CV_BGR2GRAY;

you can use CV_BGR2GRAY after this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top