📜  Python OpenCv:在视频上写文字

📅  最后修改于: 2022-05-13 01:55:03.977000             🧑  作者: Mango

Python OpenCv:在视频上写文字

OpenCV 是用于计算机视觉、机器学习和图像处理的庞大开源库,现在它在实时操作中发挥着重要作用,这在当今的系统中非常重要。通过使用它,人们可以处理图像和视频以识别物体、面部,甚至是人类的笔迹。

cv2.putText()方法在用户指定的所需位置的视频帧上插入文本。我们可以设置字体类型以及颜色和粗细。

例子:

# Python program to write
# text on video
  
  
import cv2
  
  
cap = cv2.VideoCapture('sample_vid.mp4')
  
while(True):
      
    # Capture frames in the video
    ret, frame = cap.read()
  
    # describe the type of font
    # to be used.
    font = cv2.FONT_HERSHEY_SIMPLEX
  
    # Use putText() method for
    # inserting text on video
    cv2.putText(frame, 
                'TEXT ON VIDEO', 
                (50, 50), 
                font, 1, 
                (0, 255, 255), 
                2, 
                cv2.LINE_4)
  
    # Display the resulting frame
    cv2.imshow('video', frame)
  
    # creating 'q' as the quit 
    # button for the video
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
  
# release the cap object
cap.release()
# close all windows
cv2.destroyAllWindows()

输出:

python-write-to-video-opencv