0

I have an image for which I need to do Handwriting Recognition on Android Client using TFLite.

To test this, I cut some portions of the image and passed them to the model but was getting very poor accuracy despite the model being 90% accurate.

For further debugging, I was checking if my cutting part was correct. The following code is the one which I use to crop my image.

Bitmap test = Bitmap.createBitmap(src, 494,213,30, 33);

When I do this,

new Thread() {
        @Override
        public void run() {
            try (FileOutputStream out = new FileOutputStream(path+"/test.jpg")) {
                (test).compress(Bitmap.CompressFormat.JPEG, 100, out); // bmp is your Bitmap instance
                // PNG is a lossless format, the compression factor (100) is ignored
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }.start();

The image gets properly saved to my storage.

enter image description here

But, I tried something like this.

for(int i =0;i<30;i++){
     for(int j=0;j<33;j++){
        System.out.print(Color.red(test.getPixel(i,j))+" ");
     }
     System.out.println();
}

I used the matrix and formed the following image. enter image description here

As you can see, my original bitmap of 1 part is rotated.

Can someone please explain why this is happening ?? And some alternative approach to this will help as well

Thanks in Advance.

Update: I tried the following

ExifInterface ei= null;
try {
   ei = new ExifInterface(root+"/test.jpg");
} catch (IOException e) {
   e.printStackTrace();
}
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_UNDEFINED);
System.out.println("Orientation is "+orientation);

My Output is:

Orientation is 0

Phenomenal One
  • 2,501
  • 4
  • 19
  • 29
  • 1
    If you are taking photo from camera than there is the problem! Because some camera recognition of image as portrait and landscape is different as them own way! So, you need to re-rotate image by checking its right degree using `ExifInterface` – Nick Bapu May 23 '19 at 10:48
  • Look at [this question](https://stackoverflow.com/questions/14066038/why-does-an-image-captured-using-camera-intent-gets-rotated-on-some-devices-on-a) before someone put your question as duplicate! – Nick Bapu May 23 '19 at 10:52
  • Possible duplicate of [Why does an image captured using camera intent gets rotated on some devices on Android?](https://stackoverflow.com/questions/14066038/why-does-an-image-captured-using-camera-intent-gets-rotated-on-some-devices-on-a) – Manoj Perumarath May 23 '19 at 11:04
  • @NickBapu Kindly look at my updated question – Phenomenal One May 23 '19 at 11:25

0 Answers0