OpenCV putText in Python

Introduction:

In this tutorial, we are learning about the OpenCV putText in Python. The OpenCV is a Python binding library designed to solve computational vision problems. The cv2.putText() method is used for drawing a line of text over each image. OpenCV putText() is a command available in the OpenCV library used to put text on a user provided image using the text function. The function is defined in the img proc.hpp header of the python programming language. To place text on a specific image as the user desires, you must first declare the matrix that runs on loading the desired image. It would help if you also defined the beginning of the text in the matrix. You also need to define the font color of the text, the font style of the text, and the weights set for the text. This function is available in the OpenCV library of the Python programming language, a solution designed to solve computer vision problems.

Syntax:

The syntax of the OpenCV putText in Python is given below -

Parameters:

The parameters of the OpenCV putText in Python are given below -

  1. image: The image parameter shows the original image on the system when the user selects to add text by the system.
  2. text: The text parameter represents the text that the system should draw as specified by the user.
  3. org: The org parameter is used to represent the coordinates of the text relative to the left corner of the image. These coordinates are represented by passing 2 values representing X and Y coordinates.
  4. font: The font parameter is used to specify the type or style of the font and is used to represent user-specified text. Here are some examples of font types that can be used: FONT_HERSHEY_PLAIN OR FONT_ HERSHEY_SIMPLEX.
  5. fontScale: The fontScale parameter represents what is best for font size and is related to the font scale, which acts as an equation for the dimensions of the text to be entered.
  6. color: The color parameter represents the specific color that should be given to the text input in the drawing on the screen. This color is extracted from the BGR tuple passed to it. For example, the tuple for blue colour text would be (255, 0, 0).
  7. thickness: The thickness parameter specifies the thickness of the text line entered by the user. It is measured in pixel size.
  8. lineType: The lineType parameter defines the line to be used for the text to be entered into the image. This parameter is optional.
  9. bottomLeftOrigin: The bottomLeftOrigin parameter defines the position of the image data location relative to the directional position in the image. This parameter is optional. If this parameter is taken as true, then the location of the image data can be seen in the lower left part of the image. If false, then the location of the image data is in the upper left corner of the image.

Return Value:

The return value of the OpenCV putText in Python is given below -

This method is responsible for returning the output image to be loaded from the specified file.

Program Code 1:

Here we give a program code of the OpenCV putText method in Python. The code is given below -

Output:

Now, we run the above code and find the image after putting a test in the given image. Then the output is given below -

OpenCV putText in Python

Program Code 2:

Here we give another program code of the OpenCV putText method in Python. The code is given below -

Output:

Now, we run the above code and find the image after putting a test in the given image. Then the output is given below -

OpenCV putText in Python

Conclusion:

So, by this tutorial we are learning about the OpenCV putText in Python. The OpenCV putText() method is a useful feature in the OpenCV library that allows the system to add text to a user provided image. In many graphic environments, text must match the associated image, and there must be a variety of colors, font styles, widths, and orientations to determine where on the page the text should be placed in the photo. It is easy to use using the put text method. It also reduces the level of detail of the written program and increases the overall execution speed of the program. Here, we also learn some program code for putting text in the given image.