Eclipse在使用javacv时显示OpenCV cvCvtColor的错误

时间:2012-03-04 22:13:24

标签: android opencv javacv

我使用javaCV作为我的Android应用程序: 当我试图将图像转换为灰度图像时,eclipse无法找到常量CV_BGR2GRAY。

任何人都可以帮助我吗?谢谢。

  cvCvtColor(originalImage,grayImage,CV_BGR2GRAY);

另外, eclipse无法在

中找到CASCADE_FILE的常量
 CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(cvLoad(CASCADE_FILE));

4 个答案:

答案 0 :(得分:5)

我在C / C ++版本中使用OpenCV,但我指出的概念仍然有效。

OpenCV常量CV_BGR2GRAY属于源文件types_c.h中定义的枚举类型:

  

/ *颜色转换的常量* /

     

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

首先检查库的源文件中是否正确包含了types_c.h头文件:在我的UNIX系统上,我在路径/usr/local/include/opencv2/imgproc/types_c.h找到它。

如果它存在,可能只是编译选项中的问题:确保您正确包括链接所有库文件。

在我的情况下,我使用以下内容指定了库的搜索路径:

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

显然包含了编译器的库:

  • -I/usr/local/include/opencv

如果它仍然不起作用,只需尝试调用函数cv::cvCvtColor()指定值6作为最后一个输入参数(它是对应于枚举类型的 int 常数CV_BGR2GRAY):

cvCvtColor(originalImage,grayImage, 6 );

关于你的第二个错误,我不知道该说些什么,可能是由于我之前说过的同样问题。

检查解析第一个是否也修复了第二个。

请在您的问题中付出更多努力!

答案 1 :(得分:1)

我认为这个常数是:org.opencv.imgproc.ImgProc.COLOR_BGR2GRAY

为什么它不是CV_BGR2GRAY是将C接口自动转换为Java的人工制品。

(如果您了解OpenCV Java,那么问题就非常清楚和相关。如果您不这样做,为什么要发布关于C / C ++接口的100行并对提问者抱怨)。

答案 2 :(得分:0)

这里“import org.opencv.imgproc.Imgproc”

答案 3 :(得分:0)

请在ActivityClass文件的顶部导入此静态参数。

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

此后可以使用CV_BGR2GRAY。