首页 > 解决方案 > cover text inside an image with firebase

问题描述

I'm trying to make sure that all the writings are covered in a preloaded photo. for that im using firebase ml libraries(on-device, not cloud api).

I'm currently trying with the rect and giving it the coordinates that it reads from the block like that:

imageViewArray[i].setRight(blockFrame.right);
imageViewArray[i].setLeft(blockFrame.left);
imageViewArray[i].setTop(blockFrame.top);
imageViewArray[i].setBottom(blockFrame.bottom);

i didnt see any error but nothing change in my app.. where i wrong?

another thing: as i read here getCornerPoint() create a Point[] with the axis x and y about all 4 corners.. can these be useful to me to create an imageview that is placed in the same area?

this is my onStart() in MainActivity:

    protected void onStart() {
        super.onStart();
        FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
        FirebaseVisionTextRecognizer textRecognizer = FirebaseVision.getInstance()
                .getOnDeviceTextRecognizer();

        final Task<FirebaseVisionText> result =
                textRecognizer.processImage(image)
                        .addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
                            @Override
                            public void onSuccess(FirebaseVisionText firebaseVisionText) {
                                // Task completed successfully
                                Integer i = 0;
                                resultText = firebaseVisionText.getText();
                                output = resultText;
                                tvResult.setText(output);
                                for (FirebaseVisionText.TextBlock block: firebaseVisionText.getTextBlocks()) {
                                    String blockText = block.getText(); //prende il testo e lo mette nella stringa
                                    Float blockConfidence = block.getConfidence(); //bho
                                    List<RecognizedLanguage> blockLanguages = block.getRecognizedLanguages(); //rileva la lingua
                                    Point[] blockCornerPoints = block.getCornerPoints(); //prende le coordinate della box
                                    Rect blockFrame = block.getBoundingBox();

                                    ImageView[] imageViewArray = new ImageView[50];
                                    imageViewArray[i] = new ImageView(context);
                                    imageViewArray[i].setBackgroundColor(Color.rgb(255, 0, 0));
                                    imageViewArray[i].setRight(blockFrame.right);
                                    imageViewArray[i].setLeft(blockFrame.left);
                                    imageViewArray[i].setTop(blockFrame.top);
                                    imageViewArray[i].setBottom(blockFrame.bottom);

                                    i++;
                                }
                            }
                        })
                        .addOnFailureListener(
                                new OnFailureListener() {
                                    @Override
                                    public void onFailure(@NonNull Exception e) {
                                        // Task failed with an exception
                                    }
                                });
}

标签: javaandroidfirebasefirebase-mlkit

解决方案


推荐阅读