Android Question Problems with Mobile Vision 1.51

colboy

Member
Licensed User
Longtime User
I've been using DonManfred's Mobile Vision library for a while and not had any issues. However an application I have written has now been deployed to a client with 24 tablets the same as mine, Galaxy Tab A 8", they are reporting that the scanning function I created isn't working. Basically the users presses a scan button and a new Activity is created along with a form with a preview. I'm using CamEx2 to take the picture, which is working fine and then feeding the saved bitmap to MobileVision to extract the barcodes. On my tablet I have not had any issues.

Without giving all of the code, here's the steps in my activity relating to MobileVision.

1. On Globals - Dim barcode As BarcodeDetector
2. In Activity_Create - barcode.Initialize("Barcode")
3. Here's my TakePicture Sub

B4X:
Sub TakePicture
    Try
        SetState(openstate, True, False)
        Wait For(cam.FocusAndTakePicture(MyTaskIndex)) Complete (Data() As Byte)
        SetState(openstate, False, False)
    
        '''
        lstBarcodes.AddSingleLine("Picture File Length: "&Data.Length)
    
        Dim bmp As Bitmap = cam.DataToBitmap(Data)
        Dim lDateTime As String
        Dim Out As OutputStream
        lDateTime=GlobalFunctions.GetStampDateTime(DateTime.now).Replace(":","")
        Try
            Out = File.OpenOutput(File.Dirinternal, "PI-"&lDateTime&".jpg", False)
            bmp.WriteToStream(Out, 50, "JPEG")
            Out.Close
        Catch
            lstBarcodes.AddSingleLine("Error Saving File: "&LastException)
        End Try

        Dim l As String
        Dim su As StringUtils

        If File.Exists(File.Dirinternal,"PI-"&lDateTime&".jpg")=False Then
            lstBarcodes.addsingleLine("File Wasn't Found: "&File.Dirinternal&"\PI-"&lDateTime&".jpg")
        Else
            l=su.EncodeBase64(GlobalFunctions.FileToBytes(File.Dirinternal, "PI-"&lDateTime&".jpg"))
            If GlobalFunctions.gScan.ImageContent="" Then
                GlobalFunctions.gScan.ImageContent=l
            End If
        End If

        If barcode.isOperational Then
            barcode.scanBitmap(bmp)
        Else
            lstBarcodes.addsingleLine("Barcode decoder is not showing as active")
        End If
        Log("Picture taken: " & bmp)
    Catch
        HandleError(LastException)
    End Try
End Sub

As I said I've never had an issue, but on the users tablets they are sometimes scanning, but most of the time it fails at the line checking if lBarcode.isOperational. Any clues of what it might be?

Thanks

Colin
 

walterf25

Expert
Licensed User
Longtime User
I've been using DonManfred's Mobile Vision library for a while and not had any issues. However an application I have written has now been deployed to a client with 24 tablets the same as mine, Galaxy Tab A 8", they are reporting that the scanning function I created isn't working. Basically the users presses a scan button and a new Activity is created along with a form with a preview. I'm using CamEx2 to take the picture, which is working fine and then feeding the saved bitmap to MobileVision to extract the barcodes. On my tablet I have not had any issues.

Without giving all of the code, here's the steps in my activity relating to MobileVision.

1. On Globals - Dim barcode As BarcodeDetector
2. In Activity_Create - barcode.Initialize("Barcode")
3. Here's my TakePicture Sub

B4X:
Sub TakePicture
    Try
        SetState(openstate, True, False)
        Wait For(cam.FocusAndTakePicture(MyTaskIndex)) Complete (Data() As Byte)
        SetState(openstate, False, False)
   
        '''
        lstBarcodes.AddSingleLine("Picture File Length: "&Data.Length)
   
        Dim bmp As Bitmap = cam.DataToBitmap(Data)
        Dim lDateTime As String
        Dim Out As OutputStream
        lDateTime=GlobalFunctions.GetStampDateTime(DateTime.now).Replace(":","")
        Try
            Out = File.OpenOutput(File.Dirinternal, "PI-"&lDateTime&".jpg", False)
            bmp.WriteToStream(Out, 50, "JPEG")
            Out.Close
        Catch
            lstBarcodes.AddSingleLine("Error Saving File: "&LastException)
        End Try

        Dim l As String
        Dim su As StringUtils

        If File.Exists(File.Dirinternal,"PI-"&lDateTime&".jpg")=False Then
            lstBarcodes.addsingleLine("File Wasn't Found: "&File.Dirinternal&"\PI-"&lDateTime&".jpg")
        Else
            l=su.EncodeBase64(GlobalFunctions.FileToBytes(File.Dirinternal, "PI-"&lDateTime&".jpg"))
            If GlobalFunctions.gScan.ImageContent="" Then
                GlobalFunctions.gScan.ImageContent=l
            End If
        End If

        If barcode.isOperational Then
            barcode.scanBitmap(bmp)
        Else
            lstBarcodes.addsingleLine("Barcode decoder is not showing as active")
        End If
        Log("Picture taken: " & bmp)
    Catch
        HandleError(LastException)
    End Try
End Sub

As I said I've never had an issue, but on the users tablets they are sometimes scanning, but most of the time it fails at the line checking if lBarcode.isOperational. Any clues of what it might be?

Thanks

Colin
Is hard to say without looking at what's else is going on on the rest of your code, but I also had a similar issue on an app I created for a client where i'am using the CamEx2 class and it was causing all kinds of issues when they would open up the camera view to take pictures, most of the issues were related to the Focusing of the camera, sometimes they would press on the Take Picture button too quick before the camera could focus properly and then all hell would break loose, what I did to get around that was to disable the Take a Picture button until the camera focused.

Not sure if this could be the same on your end but it's worth looking into it.

Regards,
Walter
 
Upvote 0

colboy

Member
Licensed User
Longtime User
Would I be doing something impractical if I did something like the following:
B4X:
Try
   barcode.initialize("Barcode")
   If barcode.isOperational Then
      barcode.scanBitmap(bmp)
   Else
      lstBarcodes.addsingleLine("Barcode decoder is not showing as active")
   End If
   barcode.release
Catch
   'Error
End Try

so basically the barcode reader would get initialized every time a picture is taken. Just trying to think out loud, as it's hard to debug when everything on my machine works fine. Also is there anyway to find out why IsOperation would be false?

Colin
 
Upvote 0

colboy

Member
Licensed User
Longtime User
Is hard to say without looking at what's else is going on on the rest of your code, but I also had a similar issue on an app I created for a client where i'am using the CamEx2 class and it was causing all kinds of issues when they would open up the camera view to take pictures, most of the issues were related to the Focusing of the camera, sometimes they would press on the Take Picture button too quick before the camera could focus properly and then all hell would break loose, what I did to get around that was to disable the Take a Picture button until the camera focused.

Not sure if this could be the same on your end but it's worth looking into it.

Regards,
Walter
I don't think it's a camera issue. I've been very vigorous in testing, forcing blurry pics, etc. I did have an issue when the scan result was returning null, bet all was fine once I captured this.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
I don't think it's a camera issue. I've been very vigorous in testing, forcing blurry pics, etc. I did have an issue when the scan result was returning null, bet all was fine once I captured this.
Do you know exactly where the app is crashing on your client's side?

Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
It's not crashing. It's just when my program checks to see if barcode.IsOperational, it's false.
I see, i'm not familiar with this Barcode library, but if barcode.Isoperational is returning false then there's obviously something going on, you should try to take out the Try Catch code to see if you get any error?

Walter
 
Upvote 0
Top