Java 将OpenCV mat转换为Android位图

Java 将OpenCV mat转换为Android位图,java,android,opencv,bitmap,Java,Android,Opencv,Bitmap,我正在尝试将OpenCV mat转换为android位图,但这会给我带蓝色的图像(黄色变为蓝色)!即使我没有对图像进行任何处理!我不知道为什么会这样。以下是一些相关代码: File file = new File(imgDecodableString); image = Imgcodecs.imread(file.getAbsolutePath(),Imgcodecs.CV_LOAD_IMAGE_COLOR); resultBitmap = Bitmap.createBitmap(image.c

我正在尝试将OpenCV mat转换为android位图,但这会给我带蓝色的图像(黄色变为蓝色)!即使我没有对图像进行任何处理!我不知道为什么会这样。以下是一些相关代码:

File file = new File(imgDecodableString);
image = Imgcodecs.imread(file.getAbsolutePath(),Imgcodecs.CV_LOAD_IMAGE_COLOR);
resultBitmap = Bitmap.createBitmap(image.cols(),  image.rows(),Bitmap.Config.ARGB_8888);;
Utils.matToBitmap(image, resultBitmap);
Bitmap mResult = resultBitmap;
ImageView imgView = (ImageView) findViewById(R.id.imgView);
imgView.setImageBitmap(mResult);
//imgView.setImageBitmap(BitmapFactory.decodeFile(imgDecodableString));
我是android应用程序开发新手,所以我可能错过了一些简单的东西。谢谢你的帮助

编辑:

我上传图片以供参考


正如所怀疑的,问题在于
RGB
颜色约定,Android遵循
RGB
颜色约定,但OpenCV遵循
BGR
颜色约定,您可以使用
Imgproc.cvtColor(mat,Imgproc.color\u BGR2RGBA)
,在将其显示在
图像视图

中之前,根据给出的建议,我制作了一个将Mat转换为位图的函数。这个功能工作得很好

private static Bitmap convertMatToBitMap(Mat input){
    Bitmap bmp = null;
    Mat rgb = new Mat();
    Imgproc.cvtColor(input, rgb, Imgproc.COLOR_BGR2RGB);

    try {
        bmp = Bitmap.createBitmap(rgb.cols(), rgb.rows(), Bitmap.Config.ARGB_8888);
        Utils.matToBitmap(rgb, bmp);
    }
    catch (CvException e){
        Log.d("Exception",e.getMessage());
    }
    return bmp;
}

你能不能也上传这两张图片,我怀疑有一些RGB2BGR的问题,但查看你的源代码似乎不太可能。@ZdaR我已经上传了图片。请看一看你的意思是:Imgproc.cvtColor(image,image,Imgproc.COLOR\u RGB2GRAY,4);因为它成功了!谢谢