本文介绍了使用android相机捕获图像后将位图转换为Mat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mat b = new Mat();
Bitmap bmp = getIntent().getExtras().getParcelable("image_send");

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_image);
    Mat tmp = new Mat (bmp.getWidth(), bmp.getHeight(), CvType.CV_8UC1);
    Utils.bitmapToMat(bmp, tmp);
    Imgproc.cvtColor(tmp, tmp, Imgproc.COLOR_RGB2GRAY);
    //Imgproc.cvtColor(tmp, tmp, Imgproc.COLOR_GRAY2RGB, 4);
    Utils.matToBitmap(tmp, bmp);

    iv = (ImageView) findViewById(R.id.imageView1);
    iv.setImageBitmap(bmp);
}

无法显示 bmp.我的应用在拍照后停止了.

Can't display the bmp. My app has stopped after taking a picture.

推荐答案

Utils.bitmapToMat 将 Android 位图转换为 OpenCV Mat.它需要 ARGB_8888RGB_565 类型的位图.

import org.opencv.android.Utils;

Mat mat = new Mat();
Bitmap bmp32 = bmp.copy(Bitmap.Config.ARGB_8888, true);
Utils.bitmapToMat(bmp32, mat);

这篇关于使用android相机捕获图像后将位图转换为Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-17 01:49