java如何使用OpenCV将图像转换为黑白图像并在ANDROID中消除阴影
我有一个将RGB位图转换为黑白位图的代码,使用以下代码:
public static Bitmap setDefaultValues(Bitmap bmp) {
Mat srcMat = new Mat();
org.opencv.安卓.Utils.bitmapToMat(bmp, srcMat, true);
final Bitmap bitmap = Bitmap.createBitmap(srcMat.clone().width(), srcMat.clone().height(), Bitmap.Config.ARGB_8888);
Imgproc.cvtColor(srcMat, srcMat, Imgproc.COLOR_BGR2GRAY, 0);
Mat srcMat1 = srcMat;
Imgproc.GaussianBlur(srcMat1, srcMat1, new Size(3, 3), 0);
//Mat srcMat1 = new Mat(srcMat.rows(), srcMat.cols(), CV_8UC1);
//int kernalsize = 3;
//Imgproc.bilateralFilter(srcMat, srcMat1, kernalsize, kernalsize * 2, kernalsize / 2);
srcMat1.convertTo(srcMat1, 0, 1.9, -120);
srcMat1.convertTo(srcMat1, CvType.CV_8U, 1.9, -120);
Imgproc.cvtColor(srcMat1, srcMat1, Imgproc.COLOR_GRAY2RGBA, 4);
org.opencv.安卓.Utils.matToBitmap(srcMat, bitmap, true);
return bitmap;
}
我已经实现了将RGB图像转换成黑白的代码。 这是返回我的权利,但我的问题是在这里,我不能从图像中删除阴影
我还比较了其他应用程序,这是完美的转换,我不明白我错在哪里
所以请帮助我如何实现我的目标
# 1 楼答案
请使用以下代码将彩色图像转换为黑白
# 2 楼答案
如果你能找到解决方案,请试试这个
# 3 楼答案
请看这条线上的答案。他已解释并提供了良好的输出结果。 @Threshold image using opencv (Java)