1.app的build.gradle中添加依赖
implementation ‘com.quickbirdstudios:opencv:4.3.0‘
2.MainActivity中判断成功与否
if (!OpenCVLoader.initDebug()) Log.e("OpenCv", "Unable to load OpenCV"); else Log.d("OpenCv", "OpenCV loaded");
3.将bitmap图片转为mat
Mat srcv = new Mat(bitmapNew_x.getHeight(), bitmapNew_x.getWidth(), CvType.CV_8UC4);
Utils.bitmapToMat(bitmapNew_x, srcv);// turn bitmap into mat
4.将mat转为bitmap
final Bitmap lunju_x = bitmapNew_x.copy(Bitmap.Config.ARGB_8888, false); Utils.matToBitmap(srcv, lunju_x);
5.显示图片
imageView.setImageBitmap(lunju_x);