个性化阅读
专注于IT技术分析

Python OpenCv:如何在视频上编写文本?

点击下载

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

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

语法:cv2.putText(帧, 文本, org, 字体, 颜色, 粗细)
参数:
帧:视频的当前运行帧。
文本:要插入的文本字符串。
org:文本字符串的左下角
font:要使用的字体类型。
color:字体的颜色。
厚度:字体的厚度

例子:

# 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

首先, 你的面试准备可通过以下方式增强你的数据结构概念:Python DS课程。


赞(0)
未经允许不得转载:srcmini » Python OpenCv:如何在视频上编写文本?

评论 抢沙发

评论前必须登录!