EADST

Put Rectangle and Text in Video with OpenCV

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
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
站点统计

本站现有博文242篇,共被浏览290224

本站已经建立1778天!

热门文章
文章归档
回到顶部