cv3.draw.getTextSize

cv3.draw.getTextSize(text, font=None, scale=None, t=None)[source]

Calculate the width and height of a text string.

This is an experimental function. To use it, set experimental mode with cv3.opt.set_exp().

Parameters:
  • text (str) – Input text string.

  • font (int or str, optional) – Font type. Can be an OpenCV font flag or string. Available string options: ‘simplex’, ‘plain’, ‘duplex’, ‘complex’, ‘triplex’, ‘complex_small’, ‘script_simplex’, ‘script_complex’, ‘italic’. Defaults to opt.FONT.

  • scale (float, optional) – Font scale factor that is multiplied by the font-specific base size. Defaults to opt.SCALE.

  • t (int, optional) – Thickness of the lines used to draw a text. Defaults to opt.THICKNESS.

Returns:

A tuple containing:
  • Size: The size of a box that contains the specified text.

  • baseline (int): y-coordinate of the baseline relative to the bottom-most text point.

Return type:

tuple

Example

>>> import cv3
>>> # Get text size
>>> text_size, baseline = cv3.getTextSize('Hello World', font='simplex', scale=1.2, t=2)
>>> print(f"Text size: {text_size}, Baseline: {baseline}")