B4A Library Onyx

this is a wrap for this Github Project.

An android library that uses technologies like artificial Intelligence, machine learning, and deep learning to make developers understand the content that they are displaying in their app.

Please note that this lib used service from Clarifai which is not totally free (https://clarifai.com/pricing)


Onyx
Author:
DonManfred (wrapper)
Version: 1
  • OnyxTags
    Events:
    • onComplete (tags As List)
    Methods:
    • Initialize (EventName As String)
    • IsInitialized As Boolean
    • TagsandProbability
    • TagsfromApi
    • fromURL (urls As String) As Tags
    • fromVideoArray (videoArray() As Byte) As Tags
    Permissions:
    • android.permission.ACCESS_NETWORK_STATE
    • android.permission.INTERNET
    Properties:
    • Instance As Tags [write only]

In this example the following image is scanned...


B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim onyx As OnyxTags
End Sub
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    onyx.Initialize("Onyx")
    onyx.fromURL("http://www.europa-entdecken.net/fileadmin/eu-entdecken/images/frankreich/eiffelturm.jpg")
    onyx.TagsandProbability
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Onyx_onComplete(tags As List)
    For i = 0 To tags.Size -1
        Log("Tag: "&tags.Get(i))
    Next
End Sub

 

Attachments

  • OnyxEx.zip
    6.7 KB · Views: 350
  • OnyxV1.0.zip
    215.3 KB · Views: 352
Last edited:

susu

Well-Known Member
Licensed User
Longtime User
It's really nice but can I scan a local image?
 

susu

Well-Known Member
Licensed User
Longtime User
If there's no internet connection, this error occurred:

 

freedom2000

Well-Known Member
Licensed User
Longtime User
HI,

I have tried this library --> fantastic job

Here are 2 tests with my cat, with non easy pictures :


and even less easy :


I must say that I am impressed by the accuracy of the returned tags :

B4X:
lib:Raising.. onyx_oncomplete() >>>>> first image
Tag: cat-0.9843883514404297
Tag: mammal-0.9824749231338501
Tag: pet-0.9763637781143188
Tag: cute-0.9732187986373901
Tag: animal-0.9653147459030151
Tag: domestic-0.959976851940155
Tag: no person-0.9498270153999329
Tag: one-0.9343335628509521
Tag: family-0.9201111793518066
Tag: portrait-0.9160491824150085
Tag: kitten-0.909244179725647
Tag: sit-0.9080994129180908
Tag: fur-0.9052782654762268
Tag: sleep-0.900326669216156
Tag: little-0.90019690990448
Tag: looking-0.8975399732589722
Tag: eye-0.8563491106033325
Tag: young-0.8389911651611328
Tag: downy-0.8171677589416504
Tag: funny-0.8079372048377991

lib:Raising.. onyx_oncomplete() >>>>> second image
Tag: sleep-0.9827830791473389
Tag: mammal-0.9814931154251099
Tag: fur-0.9796252250671387
Tag: downy-0.9748929738998413
Tag: no person-0.9641279578208923
Tag: animal-0.9632241725921631
Tag: cover-0.9560747146606445
Tag: cat-0.9497789740562439
Tag: pet-0.948310375213623
Tag: bed-0.9481406211853027
Tag: one-0.9392414093017578
Tag: domestic-0.9365823268890381
Tag: pillow-0.9315234422683716
Tag: wear-0.9257190227508545
Tag: family-0.9140724539756775
Tag: cute-0.9100362062454224
Tag: furniture-0.9068081974983215
Tag: bedroom-0.8855085968971252
Tag: dog-0.8806296586990356
Tag: portrait-0.8717036247253418

Thank you for this lib !
 

freedom2000

Well-Known Member
Licensed User
Longtime User
For the above example I have uploaded my cat on my web site.
But I really don't know how to pass a Url to access an image on my android phone...
Has anyone succeeded in doing this ?

Basicaly my idea would be to try to set up a simple cat feeder like this one
(But only for fun of course, no commercial wish).
I imagine opening the cover plate if the cat is recognized + some other "efeatures"
 

freedom2000

Well-Known Member
Licensed User
Longtime User
I have tried to call onyx.fromVideoArray after having taken an image with CameraEx class
I wanted to pass the BytesArray but it failed : code runs but Onyx never answered

B4X:
Sub Camera1_PictureTaken (Data() As Byte)
 
    onyx.Initialize("Onyx")
    onyx.fromVideoArray(Data)
    onyx.TagsandProbability
End Sub
 

freedom2000

Well-Known Member
Licensed User
Longtime User
Finally I have found a workaround to upload my cat from my phone...

I use httpServer library.
I have been obliged to configure my router to access my Android server, but it works, you can take a picture of your cat and give it to Onyx

 

freedom2000

Well-Known Member
Licensed User
Longtime User
Hi,

Just for fun I have coded a small App which is a merge of HttpServer, CameraEx and Onyx lib.

Here is the result and the source code

Thanks again @DonManfred for this impressive lib



It should compile... Just change the IP Address of your router

B4X:
ub Camera1_PictureTaken (Data() As Byte)
    Dim filename As String = "1.jpg"
    Dim dir As String = File.DirInternalCache
   
    camEx.SavePictureToFile(Data, dir, filename)
    camEx.StartPreview 'restart preview
   
    'send a broadcast intent to the media scanner to force it to scan the saved file.
    Dim Phone As Phone
    Dim i As Intent
    i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
        "file://" & File.Combine(dir, filename))
    Phone.SendBroadcastIntent(i)
    'ToastMessageShow("Picture saved." & CRLF  & "File size: " & File.Size(dir, filename), True)
    EdtOnyx.Text = ""
    onyx.Initialize("Onyx")
    onyx.fromURL("http://YOUR_Address:5555/1.jpg")
    onyx.TagsandProbability
End Sub
 

Attachments

  • Onyx.zip
    14 KB · Views: 286

petr4ppc

Well-Known Member
Licensed User
Longtime User
Dear friends,

it not functioned. As is in this threat wrote - because of pricing and licencing. We must have API key, its true? But where I must put this key?

Best regards
p4ppc
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…