Android Question Intent based camera in Android 4.x and 7.x for OCR

peacemaker

Expert
Licensed User
Longtime User
HI, All

For OCR the picture with a text must be prepared in correct orientation (without option\setting of the picture orientation, let it be so). And photo of the max possible resolution.

If to use the intent based camera and get the photo for OCR - it's very different result under Android 4.2 and Android 7, for ex.: old Android always returns photo file with correct orientation, but Android 7 - different, and the base picture orientation is landscape (but the device was portrait during the shooting).

See the attached result set and the test source code: the app is portrait only activity.
And moreover - under Android 7 i had OutOfMemory error if tried to rotate 90 the full-sized photo from the camera. And resolution must be preserved.

1) How to rotate the picture in one app under different Android versions ? Without OOM error.
2) Or how to fix the intent camera orientation ?
 

Attachments

  • source_v.0.1_intentBasedCamera.zip
    49.9 KB · Views: 394
  • all1.png
    all1.png
    159 KB · Views: 467
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Seems, can be solved like this:

B4X:
Private exif As ExifData  'from JpegUtils lib
.
.
.

'result arrives here
Sub ion_Event (MethodName As String, Args() As Object) As Object
    If Args(0) = -1 Then
        Try
            Dim in As Intent = Args(1)
            If File.Exists(imageFolder, PhotoFileName) Then
                Photo = LoadBitmap(imageFolder, PhotoFileName)
                exif.Initialize(imageFolder, PhotoFileName)
                Log("exif.TAG_ORIENTATION=" & exif.getAttribute(exif.TAG_ORIENTATION))    '1 = portrait, always under Android 4.2; Android7: 6 - portrait, 1 - left-landscape, 3 - right landscape
                Dim test As String = exif.getAttribute(exif.TAG_ORIENTATION)
                If test <> "" Then
                    Dim Orientation As Int = test    'GetOrientation
                        If Photo.Width > Photo.Height And Orientation = 1 Then
                            'landscape to left - no need to rotate
                        else if Photo.Width > Photo.Height And Orientation = 6 Then
                            Photo = RotateBitmap90(Photo, 90)  'Android7: 6 - portrait
                            Log("RotateBitmap90")
                        else if Photo.Width > Photo.Height And Orientation = 3 Then
                            Photo = RotateBitmap90(Photo, 180)  'landscape to right
                            Log("RotateBitmap180")
                        End If
                End If
            Else If in.HasExtra("data") Then 'try to get thumbnail instead
                Dim jo As JavaObject = in
                Photo = jo.RunMethodJO("getExtras", Null).RunMethod("get", Array("data"))
            End If
Catch
    Log(LastException)
End Try
    End If
 
    If Photo.IsInitialized Then
        Activity.SetBackgroundImage(Photo)
    Else
        ToastMessageShow("Wrong photo", False)
    End If
    ProgressDialogHide
    Return Null
End Sub

And in addition in the manifest:
B4X:
SetApplicationAttribute(android:largeHeap, "true")
 
Last edited:
Upvote 0
Top