MLKIT文本识别无法从图像中获取所有数字(单个数字)

发布于 2025-01-11 16:35:41 字数 1947 浏览 2 评论 0原文

我正在尝试使用 MLKIT 文本识别从图像中获取数独板,但并非所有数字都能被识别。

这就是它的样子

我认为这些线可能会干扰检测,所以我删除了所有行(使用 如何删除所有行和图像中的边框,同时以编程方式保留文本?),但仍然不能很好地识别数字。

MLKIT 在识别个位数方面是否有困难,或者我做错了什么?

这是我正在使用的代码:

public static void recognizeTextFromImage(Mat mRGBA){

    Bitmap bitmapImage = Bitmap.createBitmap(mRGBA.cols(), mRGBA.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(mRGBA, bitmapImage);
    InputImage inImg = InputImage.fromBitmap(bitmapImage, 0);

    Task<Text> result = textRecognizer.process(inImg)
            .addOnSuccessListener(new OnSuccessListener<Text>() {
                @Override
                public void onSuccess(Text text) {
                    Log.e("MLKIT", "Task success");

                    for(Text.TextBlock block: text.getTextBlocks()){
                        String blockText = block.getText();
                        for(Text.Line line: block.getLines()){
                            for(Text.Element element: line.getElements()){
                                String elText = element.getText();
                                android.graphics.Rect rect = element.getBoundingBox();

                                Log.e("MLKIT", elText);
                                Imgproc.rectangle(mRGBA, new Point(rect.left, rect.top), new Point(rect.right, rect.bottom), new Scalar(255, 0, 255 ), 1, Imgproc.LINE_AA);
                            }
                        }
                    }
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.e("MLKIT", "Task fail");
                }
            });
}

I am trying to get a sudoku board from an image using MLKIT Text Recognition but not all numbers are getting recognized.

This is what it looks like

I thought the lines may interfere with the detection so I removed all the lines ( using the 1st solution from How to remove all lines and borders in an image while keeping text programmatically?) but still numbers are not recognized well.

Does MLKIT have difficulties in recognizing single digit numbers or I am doing something wrong?

This is the code that I'm using:

public static void recognizeTextFromImage(Mat mRGBA){

    Bitmap bitmapImage = Bitmap.createBitmap(mRGBA.cols(), mRGBA.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(mRGBA, bitmapImage);
    InputImage inImg = InputImage.fromBitmap(bitmapImage, 0);

    Task<Text> result = textRecognizer.process(inImg)
            .addOnSuccessListener(new OnSuccessListener<Text>() {
                @Override
                public void onSuccess(Text text) {
                    Log.e("MLKIT", "Task success");

                    for(Text.TextBlock block: text.getTextBlocks()){
                        String blockText = block.getText();
                        for(Text.Line line: block.getLines()){
                            for(Text.Element element: line.getElements()){
                                String elText = element.getText();
                                android.graphics.Rect rect = element.getBoundingBox();

                                Log.e("MLKIT", elText);
                                Imgproc.rectangle(mRGBA, new Point(rect.left, rect.top), new Point(rect.right, rect.bottom), new Scalar(255, 0, 255 ), 1, Imgproc.LINE_AA);
                            }
                        }
                    }
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.e("MLKIT", "Task fail");
                }
            });
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文