iOS Question Get Barcode Coordinates/Bounds

Angel Garcia

Member
Licensed User
Hi all,
I'm working on a development that needs to get an image and scan the QR/Barcodes from the camera of an iPad/iPhone, and also to get the coordinates found of the QR/Barcodes.
This post helped me out to accomplish the first part:
https://www.b4x.com/android/forum/threads/save-ibarcode-preview-as-a-bitmap.64405/page-2#posts

And this post helped to get the coordinates of a QR Code:
https://www.b4x.com/android/forum/threads/detect-qr-code-from-an-image.133587/#content

In B4A, with the google vision library, its easy to get the coordinates of QRCodes or Barcodes, but in B4i it looks that it is only supported for QR Codes, so I was wondering if there is a way to get the coordinates (bounds) from a barcode too.
Or is there any another workaround?
I was caming up with an idea to create a web service with a barcode/qrcode free source api and process the image and get back the info, but i'm worried about performance.
Please guys let me know if you have a way to accomplish this
Many thanks in advance!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This method doesn't work with barcodes.

You can use the following code to find the detected rectangle:
9e187cda-445e-4a52-a862-cf18872f485f.jpg


B4X:
Sub scanner_Detected (Codes As List)
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append("Detected code:").Append(CRLF)
    Dim corners As List = Codes.Get(0).As(NativeObject).GetField("corners")
    Panel2.Visible = True
    Dim minx = 100000, maxx = 0, miny = 100000, maxy = 0 As Int
    For Each o As Object In corners
        Dim m As Map = NSDictionaryToMap(o)
        minx = Min(minx, m.Get("X"))
        maxx = Max(maxx, m.Get("X"))
        miny = Min(miny, m.Get("Y"))
        maxy = Max(maxy, m.Get("Y"))
    Next
    Panel2.SetLayoutAnimated(0, minx, miny, maxx - minx, maxy - miny)
    sb.Append(Codes.Get(0).As(BarcodeCode).Value)
    Label1.Text = sb.ToString
    Log(sb)
End Sub


Sub NSDictionaryToMap(Dictionary As Object) As Map
    Dim NewMap As NativeObject
    NewMap = NewMap.Initialize("B4IMap").RunMethod("convertToMap:",Array(Dictionary))
    Return NewMap
End Sub

Panel2 is a B4XView panel.
 
Upvote 0

Angel Garcia

Member
Licensed User
This method doesn't work with barcodes.

You can use the following code to find the detected rectangle:
View attachment 130081

B4X:
Sub scanner_Detected (Codes As List)
    Dim sb As StringBuilder
    sb.Initialize
    sb.Append("Detected code:").Append(CRLF)
    Dim corners As List = Codes.Get(0).As(NativeObject).GetField("corners")
    Panel2.Visible = True
    Dim minx = 100000, maxx = 0, miny = 100000, maxy = 0 As Int
    For Each o As Object In corners
        Dim m As Map = NSDictionaryToMap(o)
        minx = Min(minx, m.Get("X"))
        maxx = Max(maxx, m.Get("X"))
        miny = Min(miny, m.Get("Y"))
        maxy = Max(maxy, m.Get("Y"))
    Next
    Panel2.SetLayoutAnimated(0, minx, miny, maxx - minx, maxy - miny)
    sb.Append(Codes.Get(0).As(BarcodeCode).Value)
    Label1.Text = sb.ToString
    Log(sb)
End Sub


Sub NSDictionaryToMap(Dictionary As Object) As Map
    Dim NewMap As NativeObject
    NewMap = NewMap.Initialize("B4IMap").RunMethod("convertToMap:",Array(Dictionary))
    Return NewMap
End Sub

Panel2 is a B4XView panel.
Woaa!
Thank you very much Erel!
I'll give it a shot.
 
Upvote 0
Top