2

我将javaCV用于我的 android 应用程序:当我试图将图像转换为灰度图像时,eclipse 找不到常量 CV_BGR2GRAY。

谁能帮我吗?谢谢你。

  cvCvtColor(originalImage,grayImage,CV_BGR2GRAY);

此外,eclipse 找不到 CASCADE_FILE 的常量

 CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(cvLoad(CASCADE_FILE));
4

4 回答 4

4

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

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

/* 颜色转换常量 */

枚举{

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 系统上,我在 path 找到了它/usr/local/include/opencv2/imgproc/types_c.h

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

就我而言,我使用以下内容指定了库的搜索路径:

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

显然包括编译器的库:

  • -I/usr/local/include/opencv

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

cvCvtColor(originalImage,grayImage, 6 );

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

检查解决第一个是否也解决了第二个。

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

于 2012-03-05T11:25:00.647 回答
1

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

为什么不是 CV_BGR2GRAY 是 C 接口自动转换为 Java 的产物。

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

于 2014-04-19T05:33:01.070 回答
0

这里“导入 org.opencv.imgproc.Imgproc”</p>

于 2014-02-27T07:16:00.773 回答
0

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

导入静态 org.bytedeco.javacpp.opencv_imgproc.CV_BGR2GRAY;

您可以在此之后使用 CV_BGR2GRAY 。

于 2015-05-16T09:51:38.210 回答