B4A Library OpenCV320 for B4A V1.0 (Released)

Discussion in 'Additional libraries, classes and official updates' started by JordiCP, May 22, 2017.

  1. JordiCP

    JordiCP Well-Known Member Licensed User

    I am happy to announce that OpenCv320forB4A V1.0 is (at last) available.
    (Thanks a lot to beta-testers for feedback received)

    (2017/09/27) This is a link to the library ;). I may remove or change it in the future.


    OpenCV (Open Source Computer Vision Library) is a really huge project/framework developed mainly in C++ . It is released under a BSD license. Read more here: http://opencv.org/

    OpenCV320forB4A: is a B4A library wrapper which replicates (95%) the official OpenCV 3.20 Java API for Android.
    • The lib is too big to be uploaded. If you want to use it, just PM me with your mail address and I will send it to you.
    • It is free to test and use. You can [​IMG] and this will encourage me to maintain it, and also build additional material for donators.
    • License: You can use it for your projects, but you are not allowed to distribute nor sell this library. Of course you can distribute apps that use it (remember that OpenCV itself has BSD license as stated before)
    Supported hardware is: armeabi-v7a and arm64-v8

    (There may be some inaccuracies in what I expose in this post, related to the OpenCV project, since I am relatively new to it and don't know all about its internals. If you find any, please let me know and I will correct it)

    A bit of explanation
    There exist 'official' OpenCV wrappers for different languages and platforms. Android is one of them.
    The official OpenCV 3.20 for Android API includes a lot of classes, organized in modules. But it does not include "all" the original OpenCV modules (since there are other 'experimental', non-free, or platform specific modules which may be present in other platforms but not for Android). Also, there are build options to "tune" it...

    I have played quite a lot with it this last year, with a huge project which I started with inline Java, and also translating examples or testing features. But what I have used is just a small percent of the classes and methods exposed. So, there may be some (let's hope not too many) things to fix.

    How to learn OpenCVforB4A
    If you have worked before with OpenCV, the learning curve will be easy.
    If it was using Java with OpenCV for Android, then it will be immediate, since all the methods have exactly the same syntax (except for initializers, polimorphism, and some special cases where simply I did my best).
    Anyhow, the ways that I can think of, are (will add links later, also suggestions as online tutorials,.. are welcome)
    • Attached examples.
    • B4A OpenCV Tutorials. I will write a couple of them with what I consider the most important building pieces (for instance the Mat class, which in B4A is OCVMat) and modules
    • Internet examples: there are A LOT of examples over there, written in C++, Java, Python, JavaCV. I would look for examples in the language that is easier to understand for you and then try to translate. Some tips about it (based on my experience)
    • OpenCV syntax has changed as new versions. So there is an 'old' syntax in which nearly everything started with "cv...". Since version 3.X, there was 'cleaner' organization (project was written in C++ instead of C), and there were major syntax changes.
    • JavaCV: Translating from JavaCV to OpenCV should be quite easy but not always direct. JavaCV uses a mix of the old OpenCV syntax with some of its own, and at the beginning it can be a bit confusing, but then it is also easy.
    • Python: there is a lot of material...

    First steps. Prepare for some crashes...
    • In OpenCV nearly everything takes part in the native code.
    • When we call a Sub/method/algorithm, it performs some internal checks to see if all the input data is correct. This check is perfomed in the native side. If something is not correct (wrong OCVMat dimensions, some incoherent parameters,...) it throws an exception and crashes. If we are lucky, perhaps we see in the log some clues about the check that made it crash.
    • On the good side, it is very easy to achieve results with OpenCV (check the examples). The real difficult part, as with many other things, is to fine-tune it: OpenCV has a collection of really powerful 'primitive' objects and operations, and really complex algorithms that can do many things. But it is the user who has to glue all of them to achieve the desired results.

    (from the previous Beta announcement)
    • IMPORTANT: you must take this into account:
    • OpenCV (the included binary modules) is a free(*) project, but subject to license terms as described here: http://opencv.org/
      • (*): There are some modules in the OpenCV project which are on-free, but here I am refering to the ones included in the library
    • My work: (the B4A library) is free to test and use, but you can [​IMG] for it :). I'll keep donators updated with "advanced" material and examples
    • If you are interested, please PM me with your mail address and I will send you a link with the library and some basic examples. (be patient if you don't receive it immediately, I'll do it as soon as possible).
    • There is no documentation. In short, the syntax is nearly-exactly the same as the OpenCV3.20 Java API, adding "OCV" prefix and only the minimum modifications to adapt to B4A, For reference (taking into account described syntax changes) you can look at http://docs.opencv.org/java/3.1.0/ (which is not the latest one, but the API is nearly the same).
    • It would be preferable if you have worked before with OpenCV and/or can translate examples from Java/C++ and/or simply are interested in it.
    • I recommend starting with the examples and try to understand what is done. Just experimenting can lead to crash after crash of the native libraries with nearly no useful information, and can be very discouraging.
    • I forgot, the included binaries are for ameabi-v7a and arm64-v8 devices
    Some screenshots taken from the examples
    Canny operator - Features2D - Color space conversion
    Color Blob detection

    Attached Files:

    Last edited: Sep 27, 2017
  2. MarcoRome

    MarcoRome Expert Licensed User

    Great Work ;)
    JordiCP likes this.
  3. JordiCP

    JordiCP Well-Known Member Licensed User

    New real-time image processing example which already makes use of JavaCameraView (and dramatically decreases code complexity.:))
    Needs Beta3: library and example already available for beta-testers

    The result

    The code ;)
    Sub Process_Globals
    'These global variables will be declared once when the application starts.
       'These variables can be accessed from all modules.
       Dim ocl As OCVOpenCVLoader
    End Sub

    Sub Globals
    'These global variables will be redeclared each time the activity is created.
       'These variables can only be accessed from this module.
       Dim loaded As Boolean = ocl.initDebug
    Dim P As Panel
    Dim mOpenCvCameraView As OCVJavaCameraView
    Dim mCore As OCVCore
    Dim mImgProc As OCVImgproc   
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    End Sub

    Sub Activity_Resume
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
    End Sub

    ' This Sub will be called from another thread.
    ' Here we process myMat and put results in the same OCVMat object.
    ' Its contents will be drawn on the camera sufaceView
    Public Sub frameprocessor_newFrame(myMat As OCVMat)
    'Log("processing..." )
    End Sub
    barzaghino1, ilan, Star-Dust and 5 others like this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    Great work!
    DonManfred and JordiCP like this.
  5. ilan

    ilan Expert Licensed User

    hi @JordiCP. i am interested to try this great lib out.
    what is the amount for the donation that is needed to get all updates?

    thank you
    JordiCP likes this.
  6. JordiCP

    JordiCP Well-Known Member Licensed User

    Thanks a lot for your interest @ilan ! I will PM you in some minutes with the link

    There's no minimum amount, donate only if you find it useful or like it very much ;). This will encourage me to develop more examples and perhaps custom builds which I will share with donators as gratitude. Anyway, "regular" updates (bug fixes an similar) will keep on being free.

    In fact it has been a big effort and I even paused other customer projects for some weeks (which for a freelance is not good) , but the main motivation was not money (I would have made it chargeable), it was a mix of personal challenge and also my way to give something back to the community.
  7. hasanaydin52

    hasanaydin52 Member Licensed User

    great work,
    The library I was waiting for :)
    JordiCP likes this.
  8. monki

    monki Active Member Licensed User

    Hello JordiCP
    i also would have intrest to test you libary.

    Many thanks
    Last edited: May 24, 2017
    JordiCP likes this.
  9. stu14t

    stu14t Active Member Licensed User

    I'd be interested to see the lib too

    Many thanks for creating this.

    PM on the way
    JordiCP likes this.
  10. JordiCP

    JordiCP Well-Known Member Licensed User

    Sure. I'll send the link in short:)
    stu14t likes this.
  11. hayderOICO

    hayderOICO Member Licensed User

    amazing addition to b4a. would love to give it a try too.
    JordiCP likes this.
  12. piersante

    piersante New Member Licensed User

    Very interesting library. I was looking for an OpenCV solution to test the speed of objects recognition in visible space...
    Dontation done ... thank you so much.
    JordiCP likes this.
  13. JordiCP

    JordiCP Well-Known Member Licensed User

    Thank you :) just sent you the link.
  14. kdf

    kdf New Member Licensed User

    Great libray. Thanks for sharing it.
    JordiCP likes this.
  15. rbghongade

    rbghongade Active Member Licensed User

    Dear JordiCP,
    It would indeed be a great augmentation to B4A to have the OpenCv library. Please count me in!
    Thanks for the efforts.
    JordiCP likes this.
  16. Samuel Ramirez

    Samuel Ramirez Member Licensed User

    Great work JordiCP!
    I would like to receive the library. I started a conversation.
    JordiCP likes this.
  17. lsis

    lsis Member Licensed User

    Hi, please let me give a try.
    If it works i think you need many donations.
  18. JordiCP

    JordiCP Well-Known Member Licensed User

    This example is a bit more complex and must be still optimized (so not released yet). I was "trying" to translate a camera calibration example, when I realised that I haven't much idea about cameras, focal length, ...
    So, starting from the same example I jumped onto another and got something more funny

    Must say that for "real time", if processing becomes a bit complex, Android will suffer. OpenCV algorithms are not so much optimized for mobile devices as for other plattforms (desktop). Also, some of these optimisations are only accessible from C++ but not from the standard OpenCV Android API. Hope this will be better as OpenCV is continuously evolving...;)

  19. inakigarm

    inakigarm Well-Known Member Licensed User

    Great job !! Donation made !;)
    JordiCP likes this.
  20. cledic

    cledic Member Licensed User

    Very good Jordi. :)
    JordiCP likes this.
  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