简体   繁体   中英

extract data or array from text recognition ml kit android studio

How can i extract the data and create a new array list from the text recognized with the ml kit? I think the data extract is an object. So, i need to convert the object to array first?

This is my code

Task<Text> taskResult = textRecognizer.process(gallery).addOnSuccessListener(new OnSuccessListener<Text>() {
        @Override
        public void onSuccess(Text text) {
            progressDialog.dismiss();
            String recognizedText = text.getText();
            for (Text.TextBlock block : text.getTextBlocks()) {
                String blockText = block.getText();
                //Float blockConfidence = block.getConfidence();
                Point[] blockCornerPoint = block.getCornerPoints();
                Rect blockFrame = block.getBoundingBox();
                for (Text.Line line : block.getLines()) {
                    String lineText = line.getText();
                    Float lineConfidence = line.getConfidence();
                    Point[] lineCornerPoint = line.getCornerPoints();
                    Rect lineRect = line.getBoundingBox();
                    for (Text.Element element : line.getElements()) {
                        String elementText = element.getText();
                        //Float elementConfidence = element.getConfidence();
                        Point[] elementCornerPoints = element.getCornerPoints();
                        Rect elementFrame = element.getBoundingBox();
                        //result.append(elementText);

                        //create arraylist
                        list.add(block.getLines());
                        ArrayList<CalculatorItemModel> newList = new ArrayList<>();
                        for (int i = 0; i < list.size(); i++) {
                            /*for(int j = 0; j< i.lenght; j++){
                            }*/
                        }
                    }
                    tviewDetected.setText(recognizedText);
                }
            }
        }
    })
Task<FirebaseVisionText> result =
        detector.processImage(image)
                .addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
                    @Override
                    public void onSuccess(FirebaseVisionText firebaseVisionText) {
                        // Task completed successfully
                        // ...
                    }
                })
                .addOnFailureListener(
                        new OnFailureListener() {
                            @Override
                            public void onFailure(@NonNull Exception e) {
                                // Task failed with an exception
                                // ...
                            }
                        });

String resultText = result.getText();
for (FirebaseVisionText.TextBlock block: result.getTextBlocks()) {
    String blockText = block.getText();
    Float blockConfidence = block.getConfidence();
    List<RecognizedLanguage> blockLanguages = block.getRecognizedLanguages();
    Point[] blockCornerPoints = block.getCornerPoints();
    Rect blockFrame = block.getBoundingBox();
    for (FirebaseVisionText.Line line: block.getLines()) {
        String lineText = line.getText();
        Float lineConfidence = line.getConfidence();
        List<RecognizedLanguage> lineLanguages = line.getRecognizedLanguages();
        Point[] lineCornerPoints = line.getCornerPoints();
        Rect lineFrame = line.getBoundingBox();
        for (FirebaseVisionText.Element element: line.getElements()) {
            String elementText = element.getText();
            Float elementConfidence = element.getConfidence();
            List<RecognizedLanguage> elementLanguages = element.getRecognizedLanguages();
            Point[] elementCornerPoints = element.getCornerPoints();
            Rect elementFrame = element.getBoundingBox();
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM