Ask Your Question
0

cv::puttext character width?

asked 2018-02-10 01:33:41 -0600

image description

hello. i'm develop ascii art project using opencv 3.4.0

i use puttext to draw string. but i think width of each character is different.

how can i draw same width of text or not using puttext function..

thank you

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-02-10 01:39:22 -0600

LBerger gravatar image

updated 2018-02-10 01:41:00 -0600

you can use getTextSize to get the largest size and then write each character in a cell with a width set to largest size

edit flag offensive delete link more

Comments

1

thx i do this like :

float xsize = cv::getTextSize("@", 1, 1, 1, 0).width;

for (int i = 0; i < txt.size(); i++)

{

    cv::putText(imgHSV, string(1, txt.at(i)), Point(i * xsize, 10 + (y * 1)), 1, 1, Scalar::all(0));

}
dygames gravatar imagedygames ( 2018-02-10 02:15:44 -0600 )edit

yes that's it but you can improve :

float xsize = cv::getTextSize("@", 1, 1, 1, 0).width;

for (int i = 0; i < txt.size(); i++)

{
     if (cv::getTextSize(string(1, txt.at(i)), 1, 1, 1, 0).width>xsize)
           xsize = cv::getTextSize(string(1, txt.at(i)), 1, 1, 1, 0).width;    
}
for (int i = 0; i < txt.size(); i++)
{
     cv::putText(imgHSV, string(1, txt.at(i)), Point(i * xsize, 10 + (y * 1)), 1, 1, Scalar::all(0));
}
LBerger gravatar imageLBerger ( 2018-02-10 02:25:46 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-02-10 01:33:41 -0600

Seen: 1,926 times

Last updated: Feb 10 '18