Ask Your Question
0

Problem using Imgproc.getTextSize() in java/Android

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

nicoz gravatar image

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

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 -0600 )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 -0600 )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 -0600 )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 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-10-21 03:42:06 -0600

wilsonchoo gravatar image

This worked for me, the java method getTextSize() is from "org.bytedeco.opencv.global.opencv_imgproc"


int baseline[]={0};
Size textSize=getTextSize("Hello World", FONT_HERSHEY_DUPLEX, 1,1,baseline);
int textwidth=textSize.get(0);
int textheight=textSize.get(1);
rectangle(yourMat, new Point(x1 + 2, y2 - 2), new Point(x1 + 2+textwidth, y2 - 2-textheight),RGB(255,255,0), FILLED,0,0);

edit flag offensive delete link more

Comments

org.bytedeco.opencv.global.opencv_imgproc

3rdparty wrapper, not maintained from opencv. not so useful here.

berak gravatar imageberak ( 2019-10-21 04:02:18 -0600 )edit

although its 3rd party wrapper, but the method should work the same. Please give it a try.

wilsonchoo gravatar imagewilsonchoo ( 2019-10-21 04:09:31 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-07-10 08:44:16 -0600

Seen: 1,018 times

Last updated: Jul 10 '19