我正在尝试将 bmp 文件转换为 Mat,然后将其转换为灰度。但是我无法让它工作。这是我得到的:
String filename = "/mnt/sdcard/DCIM/01.bmp";
Bitmap bmp = BitmapFactory.decodeFile(filename);
Mat imgToProcess = null;
Utils.bitmapToMat(bmp, imgToProcess);
但是无论何时使用最后一行,应用程序都会崩溃(其余时间它继续正常运行)。
其余代码将是:
Imgproc.cvtColor(imgToProcess, imgToProcess, Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(imgToProcess, imgToProcess, Imgproc.COLOR_GRAY2RGBA, 4);
Utils.matToBitmap(imgToProcess, bmp);
不过,我不知道这是否有效,因为我无法从代码的早期部分将文件转换为 Mat。查看 Utils 的文档(找到 here )我正在正确使用它,但它仍然无法正常工作。
有人能帮我吗?
最佳答案
换行:
Mat imgToProcess = null;
为此:
Mat imgToProcess = new Mat();
或者这个:
Mat imgToProcess = new Mat(bmp.getHeight(), bmp.getHeight(), CvType.CV_8UC4);
为什么不直接使用 Highgui.imread
相反?
Mat imgToProcess = Highgui.imread(filename);
关于android - Utils.bitmapToMat 崩溃的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13824131/