title: ML Kit - Android - Text Recognition - Text Orientation
body: <p>I started a new application for Text Recognition of file numbers onto shelves and I used the following ML Kit Text Recognition on Youtube:
  <a href="https://www.youtube.com/watch?v=wFmjIxzGq_Y" rel="nofollow noreferrer">Tutorial ML KIT Text Recognition</a></p>
  
  <p>It works perfectly as long as the file numbers are written horizontally.
  When the text is oriented vertically and I turn the phone in landscape position, the application take into account the orientation and the textrecognition doesn't work anymore.</p>
  
  <p>I tried to add both </p>
  
  <pre><code>&lt;activity android:name=".NameOfTheActivity" android:screenOrientation="portrait"&gt; 
  </code></pre>
  
  <p>in the manifest and 
  <code>setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)</code> or even</p>
  
  <p><code>setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR)</code> </p>
  
  <p>into the onCreate method. The activity stays in portrait mode even if the phone is in landscape position. However, the text recognition still doesn't work when using my phone in landscape position. </p>
  
  <p>The corresponding parts of the Activity code are the following :</p>
  
  <pre><code>//Event Camera View
      cameraView.addCameraKitListener(new CameraKitEventListener() {
          @Override
          public void onEvent(CameraKitEvent cameraKitEvent) {
          }
  
          @Override
          public void onError(CameraKitError cameraKitError) {
          }
  
          @Override
          public void onImage(CameraKitImage cameraKitImage) {
              //Show Dialog
              waitingDialog.show();
  
              //Processing image
              Bitmap bitmap = cameraKitImage.getBitmap();
              bitmap = Bitmap.createScaledBitmap(bitmap, cameraView.getWidth(), cameraView.getHeight(), false);
              cameraView.stop();
  
              recognizeText(bitmap);
          }
  
          @Override
          public void onVideo(CameraKitVideo cameraKitVideo) {
          }
      });
  
  private void recognizeText(Bitmap bitmap) {
      FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bitmap);
  
      FirebaseVisionTextRecognizer textRecognizer = FirebaseVision.getInstance().getOnDeviceTextRecognizer();
  
      textRecognizer.processImage(image)
              .addOnSuccessListener(new OnSuccessListener&lt;FirebaseVisionText&gt;() {
                  @Override
                  public void onSuccess(FirebaseVisionText firebaseVisionText) {
                      drawTextResult(firebaseVisionText);
                  }
              }).addOnFailureListener(new OnFailureListener() {
          @Override
          public void onFailure(@NonNull Exception e) {
              Log.d("EDMT_ERROR", e.getMessage());
          }
      });
  }
  </code></pre>
  
  <p>Does anyone has some tip to make it work or knows a tutorial that works ? I have seen an example here : <a href="https://firebase.google.com/docs/ml-kit/android/recognize-text" rel="nofollow noreferrer">Firebase example</a> in which they use a media.Image object to take into account the orientation. As I don't know how to modify the original code (which use a bitmap ), I was just trying to "deactivate" the orientation sensor so that the image/bitmap taken are exactly the same whether I am using my phone in portrait or landscape position. In that case, the recognizeText(bitmap) method should return the same answers in both case.</p>