【发布时间】:2014-01-20 17:37:55
【问题描述】:
在我的 android 应用程序中,我需要找到给定/相机捕获的图像是否模糊。 我使用 openCV 库帮助中的以下代码。但它不会总是给出正确的结果。 请帮助我,在此先感谢。
private boolean isBlurredImage(Bitmap image) {
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inDither = true;
opt.inPreferredConfig = Bitmap.Config.ARGB_8888;
int l = CvType.CV_8UC1;
Mat matImage = new Mat();
Utils.bitmapToMat(image, matImage);
Mat matImageGrey = new Mat();
Imgproc.cvtColor(matImage, matImageGrey, Imgproc.COLOR_BGR2GRAY);
Mat dst2 = new Mat();
Utils.bitmapToMat(image, dst2);
Mat laplacianImage = new Mat();
dst2.convertTo(laplacianImage, l);
Imgproc.Laplacian(matImageGrey, laplacianImage, CvType.CV_8U);
Mat laplacianImage8bit = new Mat();
laplacianImage.convertTo(laplacianImage8bit, l);
System.gc();
Bitmap bmp = Bitmap.createBitmap(laplacianImage8bit.cols(),
laplacianImage8bit.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(laplacianImage8bit, bmp);
int[] pixels = new int[bmp.getHeight() * bmp.getWidth()];
bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(),
bmp.getHeight());
if (bmp != null)
if (!bmp.isRecycled()) {
bmp.recycle();
}
int maxLap = -16777216;
for (int i = 0; i < pixels.length; i++) {
if (pixels[i] > maxLap) {
maxLap = pixels[i];
}
}
int soglia = -6118750;
if (maxLap < soglia || maxLap == soglia) {
Log.i(MIOTAG, "--------->blur image<------------");
return true;
} else {
Log.i(MIOTAG, "----------->Not blur image<------------");
return false;
}
}
【问题讨论】:
-
可以使用openCV java颜色检测来检测...
-
@VenuNalla ,在这里我只需要给定图像(颜色或背面和白色)是否模糊。
-
你的问题不完整,请详细说明...
-
@VenuNalla ,当用户从相机捕获图像时。我需要发现图像是否模糊。
-
我认为如果你使用有符号类型(或者可能更好地使用实类型)而不是无符号字符,你会得到更好的结果,因为拉普拉斯算子给你正值和负值,而不仅仅是正值。并使用 Laplcaian 绝对值与阈值进行比较。
标签: android image opencv bitmap blur