Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creation of Frame results in: No native JavaCPP library in memory. (Has Loader.load() been called?) #1305

Closed
jpsacha opened this issue Sep 27, 2019 · 10 comments

Comments

@jpsacha
Copy link
Member

jpsacha commented Sep 27, 2019

Using some of the JavaCV classes may lead to exception:

java.lang.RuntimeException: No native JavaCPP library in memory. (Has Loader.load() been called?)

Looks that JavaCV does not load JavaCPP libraries on its own. If something loads them first, there is no issue.

Simple code to reproduce the exception:

import org.bytedeco.javacv.Frame;

public class NoNativeJavaCPPBug {
    public static void main(String[] args) {
//        String s = org.bytedeco.opencv.global.opencv_core.CV_VERSION;
        Frame frame = new Frame(320, 200, 8, 1);
    }
}

If you uncomment the line with CV_VERSION there is no exception, as OpenCV wrapper will load JavaCPP libraries.

@saudet
Copy link
Member

saudet commented Sep 27, 2019

Now that JavaCPP produces a separate jnijavacpp.cpp file, the idea eventually is to make it available as a separate library, as part of JavaCPP itself, using a build process similar to the presets. This would fix corner cases like this where users try to use one of the classes from JavaCPP before loading anything else.

@razvanilin
Copy link

Hmm, just updated to 1.5.2 and I'm getting the same error. Did something change in the load order?

The error trigger on this line:

yuvImage = new Frame(imageWidth, imageHeight, Frame.DEPTH_UBYTE, 2);

And the error looks like this:

     Caused by: java.lang.RuntimeException: No native JavaCPP library in memory. (Has Loader.load() been called?)
        at org.bytedeco.javacpp.BytePointer.<init>(BytePointer.java:103)
        at org.bytedeco.javacv.Frame.<init>(Frame.java:123)
        at org.bytedeco.javacv.Frame.<init>(Frame.java:113)
        at com.eosurgical.SurgTracAndroid.camera.OpenCVActivity.initRecorder(OpenCVActivity.java:260)
        at com.eosurgical.SurgTracAndroid.camera.OpenCVActivity.startRecording(OpenCVActivity.java:288)
        at com.eosurgical.SurgTracAndroid.camera.OpenCVActivity.onCreate(OpenCVActivity.java:241)
        at android.app.Activity.performCreate(Activity.java:7894)
        at android.app.Activity.performCreate(Activity.java:7881)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3279)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3443) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:221) 
        at android.app.ActivityThread.main(ActivityThread.java:7520) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) 
     Caused by: java.lang.UnsatisfiedLinkError: No implementation found for void org.bytedeco.javacpp.BytePointer.allocateArray(long) (tried Java_org_bytedeco_javacpp_BytePointer_allocateArray and Java_org_bytedeco_javacpp_BytePointer_allocateArray__J)
        at org.bytedeco.javacpp.BytePointer.allocateArray(Native Method)
        at org.bytedeco.javacpp.BytePointer.<init>(BytePointer.java:98)
        at org.bytedeco.javacv.Frame.<init>(Frame.java:123) 
        at org.bytedeco.javacv.Frame.<init>(Frame.java:113) 
        at com.eosurgical.SurgTracAndroid.camera.OpenCVActivity.initRecorder(OpenCVActivity.java:260) 
        at com.eosurgical.SurgTracAndroid.camera.OpenCVActivity.startRecording(OpenCVActivity.java:288) 
        at com.eosurgical.SurgTracAndroid.camera.OpenCVActivity.onCreate(OpenCVActivity.java:241) 
        at android.app.Activity.performCreate(Activity.java:7894) 
        at android.app.Activity.performCreate(Activity.java:7881) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3279) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3443) 
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) 
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2040) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:221) 
        at android.app.ActivityThread.main(ActivityThread.java:7520) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) 
2019-11-25 21:59:44.642 31692-31692/? I/Process: Sending signal. PID: 31692 SIG: 9

@saudet
Copy link
Member

saudet commented Nov 26, 2019

@razvanilin Nothing changed, it's always been like that.

@razvanilin
Copy link

I was looking into this again and I found out that the issue is probably that in the previous version I was importing avutil from org.bytedeco.javacpp.avutil but now it moved to org.bytedeco.ffmpeg.global.avutil

I think that causes the javaCPP library to not load.

@razvanilin
Copy link

Is there a way to load the javaCPP library without doing String s = org.bytedeco.opencv.global.opencv_core.CV_VERSION;?

I'm using an external opencv library because I have to use the following in my app.

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;

I had to exclude the opencv module in the javacv platform to avoid clash errors during the release build.

implementation ('org.bytedeco:javacv-platform:1.5.2') {
        exclude module: "opencv"
    }

@saudet
Copy link
Member

saudet commented Dec 18, 2019

If you're using OpenCV, calling Loader.load(opencv_core.class) is the cleanest way to work around this at the moment. BTW, JavaCV includes the official Java API of OpenCV as well, so there is no need to add any other libraries to your application.

@ulohani90
Copy link

ulohani90 commented Jan 21, 2020

Still seeing this error. I am not using opencv but just using javacv version 1.5.2.

@saudet
Copy link
Member

saudet commented Jan 21, 2020

@ulohani90 If you're not using OpenCV, call Loader.load() on some other class that you're using.

saudet added a commit to bytedeco/javacpp that referenced this issue Mar 29, 2020
saudet added a commit to bytedeco/javacpp-presets that referenced this issue Mar 30, 2020
@saudet
Copy link
Member

saudet commented Mar 30, 2020

This should now be fixed with the latest commits bytedeco/javacpp@abe3cf0 and bytedeco/javacpp-presets@d49542e. Please give it a try with the snapshots: http://bytedeco.org/builds/

@timothyjward This should also fix any last remaining roadblocks for OSGi. If you find anything else that we would need to do for OSGi though, please be sure to let me know! Assuming that everything is working now, the next step would be to update presets for OpenBLAS, OpenCV, etc, before moving on to Deeplearning4j, MXNet, TensorFlow, etc.

@saudet
Copy link
Member

saudet commented Apr 15, 2020

The fix is now included in just released version 1.5.3. Thank you all for the feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants