Coder Social home page Coder Social logo

jimmyhalimi / androidopencv Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 964.35 MB

This is an example on how to compile an .so for AOSP

CMake 0.83% Java 2.05% Makefile 0.39% C++ 55.74% HTML 12.48% C 17.89% Objective-C 0.05% Python 9.72% Shell 0.20% Batchfile 0.01% Roff 0.05% GDB 0.01% JavaScript 0.07% CSS 0.01% Assembly 0.01% XC 0.22% XS 0.21% Ruby 0.01% Perl 0.07% AppleScript 0.01%

androidopencv's Introduction

In order to use the .so in android, we need to compile it with the toolchain, and push the files to /vendor/lib/

In the code we should call it like this:

First include the header and define the typedef for the prototype of our function

#include "dlfcn.h"
typedef int (*CAC_FUNC)(unsigned char *data, int width, int height);

After that we need to open it like

{
    void *data = NULL;
    data = (void *)(uint8_t *)frame->bufs[0]->buffer;

    void *handle;
    char *error;

    CAC_FUNC cac_func = NULL;

    handle = dlopen("/system/vendor/lib/libreadFrame.so", RTLD_NOW);

    if(!handle)
    {
        error = (char *)dlerror();
        LOGE("DL Open Error for libreadFrame: %s", error);
    }

    dlerror();
    *(void**)(&cac_func) = dlsym(handle, "readFrameCV");
    if(dlsym(handle, "readFrameCV") == NULL)
    {
        LOGE("readFrameCV DL Error: %s", error);
    }

    if((error = (char *)dlerror()) != NULL)
    {
        LOGE("readFrameCV dl error, exit failure: %s", error);
    }

    int tmp = cac_func((unsigned char *)data+4096, mFrameLenOffset.mp[0].width, mFrameLenOffset.mp[0].height);

    dlclose(handle);

    switch (tmp)
    {
    case 0:
        LOGE("---MERGIM_LOGS--- Function finished with return 0, image empty. tmp = %d", tmp);
        break;
    case 1:
        LOGE("---MERGIM_LOGS--- Function finished with return 1, image success. tmp = %d", tmp);
        break;
    default:
        LOGE("---MERGIM_LOGS--- Switch returned default. tmp = %d", tmp);
        break;
    }
}

To compile the example we need to call the cmake .. with the toolchain file. E.g.:

cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/jimmyhalimi/Desktop/Desktop/capture_write/toolchain/android-ndk-r17c/build/cmake/android.toolchain.cmake 

Note: please update the path for your user

androidopencv's People

Contributors

jimmyhalimi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.