Ask Your Question

How would I format my string in opencv java to implement next line via putText?

asked 2015-06-17 06:45:20 -0500

muithi gravatar image

updated 2015-06-17 06:52:39 -0500

I have formated my string to be output via putText() as follows;

String predictedResult = "1. Name :"+resultRetrieved[4] + "\r\n"+ "2. ID :"+resultRetrieved[5] + "\r\n";

in putText() I pass


and I expect to have these two lines

  1. Name: Joseph Mwema
  2. ID: IDTEST001

but I end up having this one liner

Name: Joseph Mwema?? ID: IDTEST001??

How can I get this fixed? I am developing my application using java. Someone kindly show me how to do this correctly?

edit retag flag offensive close merge delete



putText() does no linefeed, for 3 lines of text, you need 3 putText calls(at digfferent x,y locations).

also, it can handle only a small ascii subset, for any unrecognized char you get a '?',

berak gravatar imageberak ( 2015-06-17 06:48:02 -0500 )edit

Oh! let me try with 3 putText() functions.

muithi gravatar imagemuithi ( 2015-06-17 06:54:35 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-06-17 07:29:35 -0500

muithi gravatar image

updated 2015-06-18 01:54:10 -0500

berak gravatar image

Thank you berak. That did the trick. I actually did this and now I have the 2 lines as I wanted. Thanks a bunch.

double fontScale = 2;
Scalar color = new Scalar(fontScale);
Point pointXY1 = new Point(10, 10);
Point pointXY2 = new Point(10, 30);

putText(imgMat, "Name  :"+resultRetrieved[4], pointXY1 , FONT_HERSHEY_PLAIN, 0.8, color, 1, CV_AA, false);
putText(imgMat, "ID     :"+resultRetrieved[5], pointXY2 , FONT_HERSHEY_PLAIN, 0.8, color, 1, CV_AA, false);
edit flag offensive delete link more


you can use the '10101' button to format code nicely here ;)

berak gravatar imageberak ( 2015-06-18 01:54:42 -0500 )edit

Noted. Thanks for the heads up. Much appreciation.

muithi gravatar imagemuithi ( 2015-06-18 02:03:29 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-06-17 06:45:20 -0500

Seen: 661 times

Last updated: Jun 18 '15