Android:图像处理使用Catalano.Framework.1.4

Android: Image processing using Catalano.Framework.1.4

我正在使用 Catalano 框架处理图像以使其对 Tesseract-OCR 友好。阈值处理工作正常但是当我尝试 UnsharpMasking 或调整大小时我收到错误无法纠正方向:java.lang.IllegalStateException:即使我已将 BitmapFactory 选项设置为 true & 也无法在回收位图上调用 setPixels() minsdk=11.

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 4;
            options.inMutable = true;

            Bitmap bitmap = BitmapFactory.decodeFile(ImagePath, options);
            Bitmap bitmap = BitmapFactory.decodeFile(ImagePath, options);
            FastBitmap fb = new FastBitmap(bitmap);
            Grayscale grayScale = new Grayscale();
            grayScale.applyInPlace(fb);


            switch (thresholdFilterName) {
            case "Threshold":  Threshold t = new Threshold(100);
            t.applyInPlace(fb);
            break;

            case "BradleyLocalThreshold":  BradleyLocalThreshold blt = new BradleyLocalThreshold();
            blt.applyInPlace(fb);
            break;

            case "SauvolaThreshold":  SauvolaThreshold st =new SauvolaThreshold();
            st.applyInPlace(fb);
            break;

            case "NiblackThreshold":  NiblackThreshold nt =new NiblackThreshold();
            nt.applyInPlace(fb);
            break;

            case "WolfJoulionThreshold": WolfJoulionThreshold wjt =new WolfJoulionThreshold();
            wjt.applyInPlace(fb);
            break;

            default: WolfJoulionThreshold wjtD =new WolfJoulionThreshold();
            wjtD.applyInPlace(fb);
            break;

            }


            UnsharpMasking um= new UnsharpMasking();
            um.applyInPlace(fb);
        // exception is thrown here.

            Sharpen s = new Sharpen();
            s.applyInPlace(fb);

            /*int newWidth=1191;
            int newHeight=2000;



    Resize rb = new Resize(newWidth, newHeight);
          // and exception is thrown here also if i comment the above unsharpmasking.

//              ResizeBicubic rb =new ResizeBicubic(newWidth, newHeight);
//              ResizeBilinear rb = new ResizeBilinear(newWidth, newHeight);
//              ResizeNearestNeighbor rb = new ResizeNearestNeighbor(newWidth, newHeight);

            rb.applyInPlace(fb);*/


            bitmap = fb.toBitmap();
            processedImage.setImageBitmap(bitmap);

我读过有关 OCR 图像预处理的文章 ImageMagick 也很不错,但我还没有找到任何关于如何将它用于 OCR 目的的具体内容 android 我得到的只是命令行工具.我也有 reffered https://github.com/paulasiimwe/Android-ImageMagick 但这也没有太大帮助

您似乎在 Catalano 框架代码中发现了错误。考虑在 project Issues page.

上提交错误报告

在 Catalano Framework 的 UnsharpMasking classapplyInPlace 方法中,对位图调用 recycle(),导致您对该位图执行的下一个操作失败.

解决方法是从 Catalano 框架代码中删除 blur.recycle() statement

作为替代解决方法,如果您因为将 Catalano 框架代码用作 JAR 而无法访问它,则可以将 class UnsharpMasking class 你自己在一个新的 class 中并覆盖 applyInPlace 方法以删除 recycle() 语句。然后,您将从代码的替代版本中引用 subclassed 版本,如下所示:

//UnsharpMasking um = new UnsharpMasking();
MySafeUnsharpMasking um = new MySafeUnsharpMasking();
um.applyInPlace(fb);