B4A Library Onyx

Discussion in 'Additional libraries, classes and official updates' started by DonManfred, Aug 14, 2016.

  1. DonManfred

    DonManfred Expert Licensed User

    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... eiffelturm.jpg


    Code:
    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
     

    Attached Files:

    Last edited: Aug 14, 2016
  2. susu

    susu Well-Known Member Licensed User

    It's really nice but can I scan a local image?
     
  3. DonManfred

    DonManfred Expert Licensed User

    1. Use a loacal url. Don´t know how to get it :D
    2. get the bytes of the image and use
    Code:
    fromVideoArray (videoArray() As Byte)
    At least the second is just a guess! I just wrote the wrapper a hour ago :D
     
    KMatle, lemonisdead and susu like this.
  4. susu

    susu Well-Known Member Licensed User

    If there's no internet connection, this error occurred:

     
  5. MarcoRome

    MarcoRome Expert Licensed User

    very interesting 50+ ;)
     
  6. susu

    susu Well-Known Member Licensed User

    DonManfred likes this.
  7. DonManfred

    DonManfred Expert Licensed User

    I´ve updated post #1 and added this important info! :)
     
    susu, MarcoRome and Cableguy like this.
  8. somed3v3loper

    somed3v3loper Well-Known Member Licensed User

    Sorry I liked this post thinking it does not require any online service :p
     
  9. DonManfred

    DonManfred Expert Licensed User

    You can surely remove your like if you want.
     
  10. somed3v3loper

    somed3v3loper Well-Known Member Licensed User

    Just kidding man :D
    Thanks for all your libraries and contributions they are all great
     
  11. Samuel Ramirez

    Samuel Ramirez Member Licensed User

    Hi Don,

    Have you an intention to implement the library for B4i?

    Regards,

    Samuel
     
  12. DonManfred

    DonManfred Expert Licensed User

    I´d NOT do ANY b4i library!

    So, the answer is NO.
     
  13. Samuel Ramirez

    Samuel Ramirez Member Licensed User

  14. freedom2000

    freedom2000 Well-Known Member Licensed User

    HI,

    I have tried this library --> fantastic job :)

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

    and even less easy :
    cat2.jpg

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

    Code:
    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 !
     
    Erel and DonManfred like this.
  15. freedom2000

    freedom2000 Well-Known Member Licensed 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"
     
  16. freedom2000

    freedom2000 Well-Known Member Licensed 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 :(

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

    freedom2000 Well-Known Member Licensed 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 :)

    [​IMG]
     
    KMatle and JordiCP like this.
  18. freedom2000

    freedom2000 Well-Known Member Licensed 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

    onyx.jpg

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

    Code:
    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
     

    Attached Files:

  19. petr4ppc

    petr4ppc Active Member Licensed 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
     
  20. DonManfred

    DonManfred Expert Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice