Python OpenCv: Write text on video (original) (raw)

Last Updated : 03 Jan, 2023

OpenCV is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in today’s systems. By using it, one can process images and videos to identify objects, faces, or even the handwriting of a human.

cv2.putText() method inserts a text on the video frame at the desired position specified by the user. We can style the type of font and also it’s color and thickness.

Syntax : cv2.putText(frame, Text, org, font, color, thickness)

Parameters:
frame: current running frame of the video.
Text: The text string to be inserted.
org: bottom-left corner of the text string
font: the type of font to be used.
color: the colour of the font.
thickness: the thickness of the font

Example:

import cv2

cap = cv2.VideoCapture( 'sample_vid.mp4' )

while ( True ):

`` ret, frame = cap.read()

`` font = cv2.FONT_HERSHEY_SIMPLEX

`` cv2.putText(frame,

`` 'TEXT ON VIDEO' ,

`` ( 50 , 50 ),

`` font, 1 ,

`` ( 0 , 255 , 255 ),

`` 2 ,

`` cv2.LINE_4)

`` cv2.imshow( 'video' , frame)

`` if cv2.waitKey( 1 ) & 0xFF = = ord ( 'q' ):

`` break

cap.release()

cv2.destroyAllWindows()

Output:

python-write-to-video-opencv

Similar Reads

Getting Started






Working with Images - Getting Started








Working with Images - Image Processing
































Working with Images - Feature Detection and Description









Working with Images - Drawing Functions









Working with Videos










Applications and Projects


















OpenCV Projects