如何找到给定的位图图像是android中的模糊图像或不模糊的图像

时间:2014-01-03 05:21:00

标签: android image opencv bitmap blur

在我的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;
    }
}

1 个答案:

答案 0 :(得分:2)

This是我读过的关于Out Of Focus图像的最佳文章之一。它由惠普研究人员制作,并在一些相机中实现。它基本上将图像分割成小方块(如网格中)并计算每个区域的模糊因子。之后,根据决策树做出最终决定(模糊图像与否)。

我希望这能帮助你完成工作。

祝你好运!

相关问题