lookitelecom.blogg.se

Opencv write text on image
Opencv write text on image











opencv write text on image

The font scale factor is multiplied by the font-specific base size.

opencv write text on image

  • fontScale: It is used to increase/decrease the size of your text.
  • OpenCV supports only a subset of Hershey Fonts.
  • fontFace: It denotes the type of font you want to use.
  • X represents the distance from the left edge and Y represents the distance from the top edge of the image. It is represented as a tuple of 2 values (X, Y).
  • org: It is the coordinates of the Bottom-Left corner of your text.
  • text: The text you want to write on the image.
  • img: The Image on which you want to write the text.
  • Check this link for more details about the font families supported by OpenCV.

    Opencv write text on image code#

    You can see in the code that we also have to set the location of the text again so that it should be visible. The line type to cv2.LINE_AA for antialiased line, and let’s flip the text using the last argument and setting it to true. We can also change the optional arguments’ value.įor example, let’s change the thickness of the line to 3.

    opencv write text on image

    We have used a black image in the example above, but we can also use any color image using the imread() function. The third optional argument is used to set the bottom left position as origin if it’s true, but by default, it is set to false, and it will flip the text.įor example, let’s create a black colored 512-by-512 image using the zeros() function of the numpy library and then put some random text on it using the putText() function. The second optional argument is the line type or style, set to cv2.LINE_8 by default. The first optional argument is the thickness of the line, and its value should be an integer by default. There are also three optional arguments that we can set, and if we don’t set the value of the optional argument, a default value will be used. The sixth argument is the text’s color, and its value should be an RGB triplet like (255,255,255) for white color.Īll the above arguments are required, and if one or more arguments are missing, there will be an error. The fifth argument is the font size or font scale, and its value should be of data type double. The fourth argument is the font family, which can be from the default font families of OpenCV like cv2.FONT_HERSHEY_SIMPLEX. The location’s value should be set using two integers in which the first integer defines the x-axis position and the second integer defines the y-axis position.įor example, if we set the location to (10,20), it will place the text 10 pixels away on the x-axis and 20 pixels away on the y-axis from the origin, which is at the image’s top-left. The third argument is the location on which we want to put the text, and by default, the location origin is the top-left of the image. The second argument is the text (string) we want to put on the image. The first argument of the putText() function is the image we want to put the text. We can use the putText() function of OpenCV to put text on an image with our desired color, font size, font family, and location. Use the putText() Function of Opencv to Put Text on Images in Python This tutorial will discuss putting text on images using the putText() function of OpenCV in Python.













    Opencv write text on image