如何在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;
    }
}

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

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

此致敬意!

最新更新