app/src/main/java/com/sample/MovEmt/activity/EnterStopActivity.java
private void recognizeTextOCRLocal(ComputerVisionClient client, LoadingDialogFragment dialog, File photo) {
        Executors.newSingleThreadExecutor().execute(() -> {
            System.out.println("-----------------------------------------------");
            System.out.println("RECOGNIZE PRINTED TEXT");

            // Replace this string with the path to your own image.

            try {
                Bitmap bmp = BitmapFactory.decodeFile(photo.getAbsolutePath());
                Matrix matrix = new Matrix();
                matrix.postRotate(getImageOrientation(photo.getAbsolutePath()));
                bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
                        bmp.getHeight(), matrix, true);
                FileOutputStream out = new FileOutputStream(photo);
                if (bmp.getHeight() > 1024 || bmp.getWidth() > 1024)
                    bmp = Bitmap.createScaledBitmap(bmp, 1024, 1024, true);
                bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
                out.flush();
                out.close();
                byte[] bytesArray = new byte[(int) photo.length()];
                FileInputStream fis = new FileInputStream(photo);
                fis.read(bytesArray); //read file into bytes[]
                fis.close();
                OcrResult ocrResultLocal = client.computerVision().recognizePrintedTextInStream()
                        .withDetectOrientation(true).withImage(bytesArray).withLanguage(OcrLanguages.ES).execute();


                if (ocrResultLocal != null) {
                    System.out.println();
                    System.out.println("Recognizing printed text from a local image with OCR ...");
                    System.out.println("\nLanguage: " + ocrResultLocal.language());
                    System.out.printf("Text angle: %1.3f\n", ocrResultLocal.textAngle());
                    System.out.println("Orientation: " + ocrResultLocal.orientation());

                    // Gets entire region of text block
                    boolean numberFound = false;
                    for (OcrRegion reg : ocrResultLocal.regions()) {
                        // Get one line in the text block
                        for (OcrLine line : reg.lines()) {
                            for (OcrWord word : line.words()) {
                                // get bounding box of first word recognized (just to demo)
                                if ((word.text().length() >= 3 && word.text().length() <= 4)) {
                                    try {
                                        Integer.parseInt(word.text());
                                        URL url = new URL(String.format(EndPoint.INFO_STOP, word.text()));
                                        HttpURLConnection con = null;

                                        con = (HttpURLConnection) url.openConnection();
                                        con.setRequestMethod("GET");

                                        //headers
                                        con.setRequestProperty("accessToken", Authentication.accessToken);
                                        con.setRequestProperty("Content-Type", "application/json; utf-8");
                                        con.setRequestProperty("Accept", "application/json");

                                        int status = con.getResponseCode();

                                        if (status == HttpURLConnection.HTTP_OK){
                                            String response = new ResponseReader().getResponse(con);
                                            JSONObject res = new JSONObject(response);
                                            if ("00".equals(res.getString("code"))) {
                                                runOnUiThread(() -> {
                                                    stopCode.setText(word.text());
                                                });
                                                numberFound = true;
                                            }
                                        }
                                    } catch (NumberFormatException e) {
                                    }
                                }
                            }
                        }
                    }
                    dialog.dismiss();
                    if (!numberFound) {
                        runOnUiThread(() -> {
                            Toast.makeText(getApplicationContext(), getString(R.string.recognize_stop_error), Toast.LENGTH_SHORT).show();
                            EditText stopCode = findViewById(R.id.stopCodeText);
                            stopCode.setText("");
                        });
                    }
                }
                photo.delete();
            }
            catch (Exception ex) {
                ex.printStackTrace();
                dialog.dismiss();
                runOnUiThread(() -> {
                    Toast.makeText(getApplicationContext(), getString(R.string.recognize_stop_error), Toast.LENGTH_SHORT).show();
                    EditText stopCode = findViewById(R.id.stopCodeText);
                    stopCode.setText("");
                });
            }
        });
    }
/**
     * RECOGNIZE PRINTED TEXT: Displays text found in image with angle and orientation of
     * the block of text.
     */
RECOGNIZE PRINTED TEXT: Displays text found in image with angle and orientation of
the block of text.
RECOGNIZE PRINTED TEXT : Displays text found in image with angle and orientation of the block of text .
private void recognizeTextOCRLocal(ComputerVisionClient client, LoadingDialogFragment dialog, File photo) {
        Executors.newSingleThreadExecutor().execute(() -> {
            System.out.println("-----------------------------------------------");
            System.out.println("RECOGNIZE PRINTED TEXT");
            try {
                Bitmap bmp = BitmapFactory.decodeFile(photo.getAbsolutePath());
                Matrix matrix = new Matrix();
                matrix.postRotate(getImageOrientation(photo.getAbsolutePath()));
                bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(),
                        bmp.getHeight(), matrix, true);
                FileOutputStream out = new FileOutputStream(photo);
                if (bmp.getHeight() > 1024 || bmp.getWidth() > 1024)
                    bmp = Bitmap.createScaledBitmap(bmp, 1024, 1024, true);
                bmp.compress(Bitmap.CompressFormat.JPEG, 100, out);
                out.flush();
                out.close();
                byte[] bytesArray = new byte[(int) photo.length()];
                FileInputStream fis = new FileInputStream(photo);
                fis.read(bytesArray); 
                fis.close();
                OcrResult ocrResultLocal = client.computerVision().recognizePrintedTextInStream()
                        .withDetectOrientation(true).withImage(bytesArray).withLanguage(OcrLanguages.ES).execute();
                if (ocrResultLocal != null) {
                    System.out.println();
                    System.out.println("Recognizing printed text from a local image with OCR ...");
                    System.out.println("\nLanguage: " + ocrResultLocal.language());
                    System.out.printf("Text angle: %1.3f\n", ocrResultLocal.textAngle());
                    System.out.println("Orientation: " + ocrResultLocal.orientation());
                    boolean numberFound = false;
                    for (OcrRegion reg : ocrResultLocal.regions()) {
                        for (OcrLine line : reg.lines()) {
                            for (OcrWord word : line.words()) {
                                if ((word.text().length() >= 3 && word.text().length() <= 4)) {
                                    try {
                                        Integer.parseInt(word.text());
                                        URL url = new URL(String.format(EndPoint.INFO_STOP, word.text()));
                                        HttpURLConnection con = null;
                                        con = (HttpURLConnection) url.openConnection();
                                        con.setRequestMethod("GET");
                                        con.setRequestProperty("accessToken", Authentication.accessToken);
                                        con.setRequestProperty("Content-Type", "application/json; utf-8");
                                        con.setRequestProperty("Accept", "application/json");
                                        int status = con.getResponseCode();
                                        if (status == HttpURLConnection.HTTP_OK){
                                            String response = new ResponseReader().getResponse(con);
                                            JSONObject res = new JSONObject(response);
                                            if ("00".equals(res.getString("code"))) {
                                                runOnUiThread(() -> {
                                                    stopCode.setText(word.text());
                                                });
                                                numberFound = true;
                                            }
                                        }
                                    } catch (NumberFormatException e) {
                                    }
                                }
                            }
                        }
                    }
                    dialog.dismiss();
                    if (!numberFound) {
                        runOnUiThread(() -> {
                            Toast.makeText(getApplicationContext(), getString(R.string.recognize_stop_error), Toast.LENGTH_SHORT).show();
                            EditText stopCode = findViewById(R.id.stopCodeText);
                            stopCode.setText("");
                        });
                    }
                }
                photo.delete();
            }
            catch (Exception ex) {
                ex.printStackTrace();
                dialog.dismiss();
                runOnUiThread(() -> {
                    Toast.makeText(getApplicationContext(), getString(R.string.recognize_stop_error), Toast.LENGTH_SHORT).show();
                    EditText stopCode = findViewById(R.id.stopCodeText);
                    stopCode.setText("");
                });
            }
        });
    }
private void recognizeTextOCRLocal ( ComputerVisionClient client , LoadingDialogFragment dialog , File photo ) { Executors . newSingleThreadExecutor ( ) . execute ( ( ) -> { System . out . println ( "-----------------------------------------------" ) ; System . out . println ( "RECOGNIZE PRINTED TEXT" ) ; try { Bitmap bmp = BitmapFactory . decodeFile ( photo . getAbsolutePath ( ) ) ; Matrix matrix = new Matrix ( ) ; matrix . postRotate ( getImageOrientation ( photo . getAbsolutePath ( ) ) ) ; bmp = Bitmap . createBitmap ( bmp , 0 , 0 , bmp . getWidth ( ) , bmp . getHeight ( ) , matrix , true ) ; FileOutputStream out = new FileOutputStream ( photo ) ; if ( bmp . getHeight ( ) > 1024 || bmp . getWidth ( ) > 1024 ) bmp = Bitmap . createScaledBitmap ( bmp , 1024 , 1024 , true ) ; bmp . compress ( Bitmap . CompressFormat . JPEG , 100 , out ) ; out . flush ( ) ; out . close ( ) ; byte [ ] bytesArray = new byte [ ( int ) photo . length ( ) ] ; FileInputStream fis = new FileInputStream ( photo ) ; fis . read ( bytesArray ) ; fis . close ( ) ; OcrResult ocrResultLocal = client . computerVision ( ) . recognizePrintedTextInStream ( ) . withDetectOrientation ( true ) . withImage ( bytesArray ) . withLanguage ( OcrLanguages . ES ) . execute ( ) ; if ( ocrResultLocal != null ) { System . out . println ( ) ; System . out . println ( "Recognizing printed text from a local image with OCR ..." ) ; System . out . println ( "\nLanguage: " + ocrResultLocal . language ( ) ) ; System . out . printf ( "Text angle: %1.3f\n" , ocrResultLocal . textAngle ( ) ) ; System . out . println ( "Orientation: " + ocrResultLocal . orientation ( ) ) ; boolean numberFound = false ; for ( OcrRegion reg : ocrResultLocal . regions ( ) ) { for ( OcrLine line : reg . lines ( ) ) { for ( OcrWord word : line . words ( ) ) { if ( ( word . text ( ) . length ( ) >= 3 && word . text ( ) . length ( ) <= 4 ) ) { try { Integer . parseInt ( word . text ( ) ) ; URL url = new URL ( String . format ( EndPoint . INFO_STOP , word . text ( ) ) ) ; HttpURLConnection con = null ; con = ( HttpURLConnection ) url . openConnection ( ) ; con . setRequestMethod ( "GET" ) ; con . setRequestProperty ( "accessToken" , Authentication . accessToken ) ; con . setRequestProperty ( "Content-Type" , "application/json; utf-8" ) ; con . setRequestProperty ( "Accept" , "application/json" ) ; int status = con . getResponseCode ( ) ; if ( status == HttpURLConnection . HTTP_OK ) { String response = new ResponseReader ( ) . getResponse ( con ) ; JSONObject res = new JSONObject ( response ) ; if ( "00" . equals ( res . getString ( "code" ) ) ) { runOnUiThread ( ( ) -> { stopCode . setText ( word . text ( ) ) ; } ) ; numberFound = true ; } } } catch ( NumberFormatException e ) { } } } } } dialog . dismiss ( ) ; if ( ! numberFound ) { runOnUiThread ( ( ) -> { Toast . makeText ( getApplicationContext ( ) , getString ( R . string . recognize_stop_error ) , Toast . LENGTH_SHORT ) . show ( ) ; EditText stopCode = findViewById ( R . id . stopCodeText ) ; stopCode . setText ( "" ) ; } ) ; } } photo . delete ( ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; dialog . dismiss ( ) ; runOnUiThread ( ( ) -> { Toast . makeText ( getApplicationContext ( ) , getString ( R . string . recognize_stop_error ) , Toast . LENGTH_SHORT ) . show ( ) ; EditText stopCode = findViewById ( R . id . stopCodeText ) ; stopCode . setText ( "" ) ; } ) ; } } ) ; }
RECOGNIZE PRINTED TEXT: Displays text found in image with angle and orientation of
 the block of text.
RECOGNIZE PRINTED TEXT : Displays text found in image with angle and orientation of the block of text .
// Replace this string with the path to your own image. //read file into bytes[] // Gets entire region of text block // Get one line in the text block // get bounding box of first word recognized (just to demo) //headers