Rajawali / RajawaliVuforia

Rajawali + Vuforia Augmented Reality
Other
227 stars 108 forks source link

How to integrate vuforia 4-2-3 #60

Open nguyenhoc89 opened 9 years ago

nguyenhoc89 commented 9 years ago

Now, the latest version of vuforia is 4-2-3. Can I upgrade project by override Vuforia.jar and libVufoia.so in libs and src/main/libs folder

amol-furlenco commented 9 years ago

I tried this but it did not work. Is there any plan to update this library to support v4 and v5 ?

kopihao commented 9 years ago

can you share the code pin point 3d object on an object? :)

Hema2 commented 8 years ago

Is there any idea to update vuforia to 5?

mmihhailov commented 8 years ago

Yupp. Got it working (4,5 etc). Requires some tweaking in build scripts, native files and java files. Will not post commit here just yet, because each Vuforia version requires special rebuild, but if anyone is interested, I can create instructions and post them here or send personally over the e-mail.

migmacdev commented 8 years ago

@mmihhailov how do you make it work I'm interested in the instructions, thanks

mmihhailov commented 8 years ago

With newest Rajawali, my port is not valid anymore. The video background is flipped 180 degrees on Z axis. Working on the workaround.

RandAmro commented 8 years ago

@mmihhailov please I need the instructions

mmihhailov commented 8 years ago

OK. Actually i did port the whole thing to Java as end result, but here are the instructions in general to use original C++ code.

First:

  1. Download the latest Android NDK and Vuforia SDK
  2. copy vuforia.jar to ./libs/ folder (replace the old one)
  3. copy libVuforia.so to ./libs folder (replace the old vuforia library)

Next: Since API has changed, you need to make the following changes in jni/RajawaliVuforia.cpp: change all occurencies of QCAR::ImageTracker to QCAR::ObjectTracker

Next: Changes are needed in jni/Android.mk ((change the path to your local ones, these are in my computer) LOCAL_SRC_FILES = C:/android/vuforia-sdk-android-5-0-10/build/lib/$(TARGET_ARCH_ABI)/libVuforia.so LOCAL_EXPORT_C_INCLUDES := C:/android/vuforia-sdk-android-5-0-10/build/include

Next: Changes to build.gradle for rajawalivuforia module:

add

defaultConfig{
    ndk{
        moduleName "rajawalivuforia"
    }
}

and

task buildNative(type:Exec, description: 'Compile JNI with NDK'){
    def ndkDir = 'C:/android/android-ndk-r10e'
    commandLine "$ndkDir/ndk-build.cmd",
            '-C', file('src/main/jni').absolutePath,
            '-j', Runtime.runtime.availableProcessors(),
            'all'
}

task cleanNative(type:Exec, description: 'Compile JNI with NDK'){
    def ndkDir = 'C:/android/android-ndk-r10e'
    commandLine "$ndkDir/ndk-build.cmd",
            '-C', file('src/main/jni').absolutePath,
            'clean'
}

Now you have buildNative task under 'other' menu in gradle scripts. When you run that, it should compile the native part of RajawaliVuforia. Or maybe not :) Worked for me, I sure hope I remember all the steps.

... Or if you ask nicely, I can send you the Java files, where I have ported the whole thing to Java and it seems to be working just nice :). Needs a bit tweaking, but it works. And it's all java, no tricky Java -> native -> back to Java magic.

This tweaking part is the reasoning not pushing the code back to github. A bit raw for sharing with wider audience.

rexendy commented 8 years ago

@mmihhailov : how to do it in osx 10.9.5?

mmihhailov commented 8 years ago

No idea. Never worked with osx. I guess you have to follow Google instructions, how to include and compile NDK stuff under osx with Android Studio. In essence, you need to compile newest .cpp with newest libVuforia.so:

  1. Modify .cpp code to work with new libVuforia.so
  2. Compile the native part with NDK
  3. Modify JNI layer in project to work with Rajawali native part
  4. Modify the java part to work with freshly compiled native part

Mainly reading the compiler error output nad fixing :)

rexendy commented 8 years ago

@mmihhailov : thank you but i've encountered this error:

no method with name='registerHalCamera' signature='(IIILjava/lang/String;[I[I)I' in class Lcom/qualcomm/ar/pl/CameraPreview;

JNI WARNING: JNI function FindClass called with exception pending

in Ljava/lang/Runtime;.nativeLoad:(Ljava/lang/String;Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/lang/String; (FindClass)

mmihhailov commented 8 years ago

did you update vuforia.jar also in ./app/libs folder to match your libVuforia.so ?

rexendy commented 8 years ago

yes I've updated it in rajawalivuforia/libs and all the libVuforia.so files

mmihhailov commented 8 years ago

seems that you still have .jar and .so mismatch here. What happens here is that it tries to load 'registerHalCamera' from .so with the wrong signature via .jar.

You need to verify the paths: ./rajawalivuforia/libs/Vuforia.jar ./rajawalivuforia/libs/armeabi-v7a/libVuforia.so

rexendy commented 8 years ago

yes i already changed that and also the .so files in these paths:

./rajawalivuforia/src/main/libs/armeabi-v7a ./rajawalivuforia/src/main/obj/local/armeabi-v7a

MasDennis commented 8 years ago

Sorry that you have to go through all this trouble to update to the latest Vuforia! I'll have a look at this myself when I find the time. Its been a while since the Vuforia version was updated.

rexendy commented 8 years ago

okay, Im currently using sdk vuforia 5-0-10

mmihhailov commented 8 years ago

Well, in this case it would be feasible to port it all to Java. Did it for test purposes and seems to work just fine.

Took the 'hammer' approach: Created class RajawaliVuforiaManager and ported all native code to Java to this class and then used this static class from RajawaliVuforiaRenderer and RajawaliVuforiaActivity.

Haven't found the time to get rid of the RajawaliVuforiaActivity yet :) But this is next in my task list.

RandAmro commented 8 years ago

@mmihhailov hello again! thank you a lot for your help. I do follow all your instructions but when I try to build it in the final step I found this error :

Error:(152, 21) error: method setInitParameters in class QCAR cannot be applied to given types; required: Activity,int,String found: RajawaliVuforiaActivity,int reason: actual and formal argument lists differ in length

And there is no buildNative task under 'other' menu in gradle scripts actually there is no other menu in gradle scripts. can you please help me in that ?

And I will be so grateful if you send me the java files! Thank you again.

rexendy commented 8 years ago

@mmihhailov thank you again. I would like to look at your java files also. I will be grateful if you could send me those. thank you!

mmihhailov commented 8 years ago

Will take a look, change few things. Currently performance is quite poor on weaker devices, like Samsung GT-I9100. Skips at least 3rd of frames. I suspect it has something to do with the fact that both, Vuforia and Rajawali try to use OpenGL at the same time and there is some kind of race condition. Also I suspect that the surface (video coming from camera) is rendered twice: first by Vuforia and then again by Rajawali, using each frame as texture on ScreenQuad.

RandAmro commented 8 years ago

@mmihhailov what about the error I had ? Do you know any solution for that ?

mmihhailov commented 8 years ago

@RandAmro There are few things that you need to do also in Java code. Vuforia API has changed a lot since 3.. For example, all QCAR. has changed to Vuforia.*.

If you take a look at the Java reference at developer.vuforia.com, you see that setInitParameters() signature has changed. Now it also requires the vuforia license key to be given as parameter. You can retrieve this when you register at developer.vuforia.com and ask in the License Manager section for a new key.

C'mon guys, you can figure out those simple things yourselves ;)

rexendy commented 8 years ago

@mmihhailov : how to handle this issue?

java.lang.UnsatisfiedLinkError: Native method not found: com.qualcomm.ar.pl.CameraPreview.newFrameAvailable:(IIII[BJ)V at com.qualcomm.ar.pl.CameraPreview.newFrameAvailable(Native Method) at com.qualcomm.ar.pl.CameraPreview.onPreviewFrame(CameraPreview.java:913)

eracorpuz commented 8 years ago

Hi @mmihhailov thank you for the brief explanation. But I don't quiet understand where to put this script:

task buildNative(type:Exec, description: 'Compile JNI with NDK'){ def ndkDir = 'F:\Android[COBA2]\RajawaliVuforia-master\vuforia-sdk-android-5-5-9' commandLine "$ndkDir/ndk-build.cmd", '-C', file('src/main/jni').absolutePath, '-j', Runtime.runtime.availableProcessors(), 'all' }

task cleanNative(type:Exec, description: 'Compile JNI with NDK'){ def ndkDir = 'F:\Android[COBA2]\RajawaliVuforia-master\vuforia-sdk-android-5-5-9' commandLine "$ndkDir/ndk-build.cmd", '-C', file('src/main/jni').absolutePath, 'clean' }

under 'other' menu in gradle scripts? in the build.gradle for rajawalivuforia module? is it inside the android blocks?

Sorry for the dummy question. Thank you

aalices commented 7 years ago

Has anyone fully succeeded in the integration? I think I have done what @mmihhailov was telling to do by my own, anyway I had some problems with background rendering, now it is okay but the model is floating around the target. It is not situated in the center but when I move the device, the model also moves more than it should. Are there any changes needed in calculating projectionMatrix or something else?

shadracktaeli commented 7 years ago

@mmihhailov thanks for instructions. Can you please send the java file, having a problem with native methods

ushang000 commented 7 years ago

@mmihhailov thanks for you help, use latest Vuforia SDK generate libRajawaliVuforia.so file . but when i run rajawalivuforiaexample get error log as below: com.example.rajawalivuforiaexample I/Rajawali: Native library libVuforia.so loaded com.example.rajawalivuforiaexample E/Rajawali: The library libRajawaliVuforia.so could not be loaded com.example.rajawalivuforiaexample E/art: No implementation found for void org.rajawali3d.vuforia.RajawaliVuforiaActivity.setActivityPortraitMode(boolean) (tried Java_org_rajawali3d_vuforia_RajawaliVuforiaActivity_setActivityPortraitMode and Java_org_rajawali3d_vuforia_RajawaliVuforiaActivity_setActivityPortraitMode__Z) i don't know the reason,can you disabuse for me or send cpp file and java file to me . very grateful !