librealsense icon indicating copy to clipboard operation
librealsense copied to clipboard

have no java wrapper

Open xiaosongfu opened this issue 8 years ago • 22 comments

i want to use java program language, there is no java wrapper ?

xiaosongfu avatar Apr 23 '18 03:04 xiaosongfu

Hi @xiaosongfu At the moment there isn't one (at least not an official one). We might add it in later releases, based on community feedback and demand.

dorodnic avatar Apr 23 '18 06:04 dorodnic

Thank you for your reply ^_^

xiaosongfu avatar Apr 23 '18 06:04 xiaosongfu

It looks like @edwinRNDR is working on this: https://github.com/edwinRNDR/librealsense

Gnimuc avatar Apr 23 '18 10:04 Gnimuc

Compiling works also on MacOSX if you change the gradle script and add a new target for it.

...
$.platforms.all {
    jniLibSpec.targetPlatform it.name
}

binaries.all {
    lib new JNIDependency(project)
    cppCompiler.args "-I${project.projectDir}/../../include"
    linker.args "-L${project.projectDir}/../../"
    //linker.args "-lrealsense2"

    if (targetPlatform.operatingSystem.macOsX) {
    	cppCompiler.args "-I${project.projectDir}/../../include"
        linker.args "${project.projectDir}/../../build/Debug/librealsense2.dylib"
    }

    if (targetPlatform.operatingSystem.windows) {
...

I am going to give it a try :)

cansik avatar Jul 16 '18 16:07 cansik

@cansik Thanks. I have focussed on Windows support only, the C API (which is used by my Java wrapper) on macOS has had some issues that have recently been addressed (see: https://github.com/IntelRealSense/librealsense/issues/1586).

Let me know if you can get it to work. Proper support for macOS and linux-x64 (with portable native libraries distributed in jar files) is on my wish list but I haven't had the time to figure out the build process for those.

edwinRNDR avatar Jul 17 '18 09:07 edwinRNDR

@edwinRNDR Compiling works and running too, after removing the absolute System.load commands and add relative ones (which target to the mac binaries too). I could create a pull request to your repository with the fixes for mac osx.

I also had the bug #1586 but could workaround it with a sleep in kotlin. My idea is to write a wrapper for processing, so it would be nice to have a final jar with all the prebuilt binaries.

cansik avatar Jul 17 '18 14:07 cansik

@cansik Yes please, that pull request is more than welcome!

edwinRNDR avatar Jul 17 '18 15:07 edwinRNDR

@edwinRNDR I've added all my changes to the gradle build, readme and a multi-os-native library code snippet to the Native class.

The problem I am currently facing is, that the librealsense2.dylib is not automatically bundled when building everything with gradle. I could also not directly find the code in the build script where it will be bundled? Because of that I can not create the PR, because I can not test the multi-os-native-lib-loading. Could you tell me where you bundle all the dependencies? (I could only fix this, by adding the library directly to the resources folder, which is not done automatically by the gradle script.)

I also would recommend that we change the name of the jar file to more descriptive name, for example: librealsense2java.jar

Here is the repository with the changes: https://github.com/cansik/librealsense/tree/master/wrappers/java

Update: Added the pull request (https://github.com/edwinRNDR/librealsense/pull/1), for anyone who just want to use the prebuilt jar, I have built one for you to download here: realsense-jvm-osx.zip

cansik avatar Jul 17 '18 19:07 cansik

@cansik Thank you. Bundling the native libraries is currently done by hand, exactly in the way as you describe it. This is less than ideal, but I should be able to add that step to the gradle build script.

The name of the jar can be changed. I think it would also be easier to create a separate jar for each platform instead of a monolithic one as it is really hard to get Windows/macOS/Linux binaries in one place in a single build.

edwinRNDR avatar Jul 17 '18 19:07 edwinRNDR

@edwinRNDR What is in your eyes the advantage of merging by hand over applying the PR? If you want to, I could remove the auto-formatting of the Native.java file.

Ok, so I will check if I can add the possibility of bundling to the build script.

Another thing to think about is if we really should protect the pointers from outside access. Currently all the pointers are private or protected, but the Native class has a lot of public methods which require the pointers. Wouldn't it make sense to create a getter for the pointers, so it is still possible to use the C API? (I created a branch where I already implemented it: https://github.com/cansik/librealsense/commit/f8462b4886f6c98081eabdf3c7067a947c99968e)

cansik avatar Jul 18 '18 07:07 cansik

@cansik Discard that :) I didn't see your pull request at the time I wrote that.

edwinRNDR avatar Jul 18 '18 09:07 edwinRNDR

@edwinRNDR Maybe it would make sense to open the issue page on your repository, so we can discuss the next features to implement, instead always writing here. I would like to contribute more to the library, and already implemented some methods on my branch.

cansik avatar Jul 18 '18 13:07 cansik

[Realsense Customer Engineering Team Comment] @Xiaosongfu Seems this issue has been resolved, can we close the ticket accordingly? Please update. Thanks!

@RealSense-Customer-Engineering There is still no java wrapper for Intel Realsense 2 which supports the main functionality. So no, I don't think this issue should be closed.

cansik avatar Oct 08 '18 08:10 cansik

[Realsense Customer Engineering Team Comment] @Xiaosong Sorry, the official release plan of java wrapper is still not clear yet. If you want to keep this open to wait for official release, we can keep it open.

@cansik @edwinRNDR - In the near future I don't think we will be able to add an official wrapper (the list of wrappers and platforms is really stretching our CI capabilities and we need more time to scale it). I'd like to add link to your work from the wrappers / community projects page so more people can find it, would that be Ok?

dorodnic avatar Oct 11 '18 10:10 dorodnic

Hi @dorodnic linking it is good. But a word of caution about the state of the project as I haven't been able to dedicate my time to it: The project has partial support for a likely older version of the C API and only Windows binaries are provided. It however was good enough for me to use in production; YMMV

edwinRNDR avatar Oct 12 '18 06:10 edwinRNDR

[Realsense Customer Engineering Team Comment] @Xiaosong As Dorodnic replied, we don't have the plan to add java wrapper in the near future. Considering this, is it Ok for you to close the ticket at present? You might check the release note if the feature is available later. Thanks!

@cansik I've found a Processing example for Windows (https://github.com/chungbwc/Magicandlove/tree/master/ml20181024b). Are you working on Mac? It would be a great to have the RealSense camera's working in Processing.

kasperkamperman avatar Oct 24 '18 20:10 kasperkamperman