Put Rectangle and Text in Video with OpenCV
作者:XD / 发表: 2022年2月22日 00:09 / 更新: 2022年2月22日 00:09 / 编程笔记 / 阅读量:1784
Put Rectangle and Text in Video with OpenCV
# coding=UTF-8
import cv2
def generate_video(video_name):
video = "{}.mp4".format(video_name)
result_video = "./video_label/{}.mp4".format(video_name)
cap = cv2.VideoCapture(video)
fps_video = cap.get(cv2.CAP_PROP_FPS)
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
videoWriter = cv2.VideoWriter(result_video, fourcc, fps_video, (frame_width, frame_height))
while (cap.isOpened()):
ret, frame = cap.read()
if ret == True:
# You need to change the following two lines.
cv2.rectangle(frame, (left_x_up, left_y_up), (right_x_down, right_y_down), (55,255,155), 5)
cv2.putText(frame, "Hello World!", (word_x, word_y), cv2.FONT_HERSHEY_SIMPLEX, 1, (55,255,155), 2)
videoWriter.write(frame)
else:
videoWriter.release()
break