Problem using Imgproc.getTextSize() in java/Android

asked 2019-07-10 08:44:16 -0500

nicoz gravatar image

updated 2019-07-10 09:04:12 -0500

I'm trying to get the width and height of a text to draw it extremely precise in a rectangle. My code is bellow:

String id_text = String.valueOf(i);
int baseLine[] = null;
Size idSize = Imgproc.getTextSize(id_text,Imgproc.FONT_HERSHEY_COMPLEX_SMALL,1.0,1, baseLine);
double idSizeW = idSize.width;
double idSizeH = idSize.height;
canvas.drawText(id_text, (float) (cx-0.5*idSizeW), (float) (cy+0.5*idSizeH),cor);

I'm getting the error bellow:

/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.app, PID: 13760
    java.lang.UnsatisfiedLinkError: No implementation found for double[] org.opencv.imgproc.Imgproc.n_getTextSize(java.lang.String, int, double, int, int[]) (tried Java_org_opencv_imgproc_Imgproc_n_1getTextSize and Java_org_opencv_imgproc_Imgproc_n_1getTextSize__Ljava_lang_String_2IDI_3I)
        at org.opencv.imgproc.Imgproc.n_getTextSize(Native Method)
        at org.opencv.imgproc.Imgproc.getTextSize(Imgproc.java:3897)

When I give a look in the line 3897 of Imgproc.java, it seems that my variable types fits the required by the function.

I don't know what I'm doing wrong, could anyone please help me? Thanks a lot!

edit retag flag offensive close merge delete

Comments

is that ALL of your code ? do you load the opencv native libs somewhere ?

(it might be just the 1st opencv function to be found, not specifically getTextSize() )

berak gravatar imageberak ( 2019-07-10 08:49:13 -0500 )edit

The complete code has about 300 lines, it makes a lot of other things. I'm loading the opencv libraries with: import org.opencv.core.Size; import org.opencv.imgproc.Imgproc;

nicoz gravatar imagenicoz ( 2019-07-10 08:55:29 -0500 )edit

look at the error, it does not find the native jni function, it's not about importing java classes (which are only wrappers around c++ code)

look at your System.loadLibrary or similar again.

berak gravatar imageberak ( 2019-07-10 12:49:36 -0500 )edit

I'm not using a native library wrote by me, I'm using the implementation in https://github.com/quickbirdstudios/o...

nicoz gravatar imagenicoz ( 2019-07-12 08:47:20 -0500 )edit