欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

python对视频画框标记后保存的方法

程序员文章站 2022-05-02 11:32:36
需要画框取消注释rectangle import cv2 import os,sys,shutil import numpy as np # open...

需要画框取消注释rectangle

import cv2
import os,sys,shutil
import numpy as np
 
# open the input movie file, input the filepath as
input_filepath = sys.argv[1]
input_movie = cv2.videocapture(input_filepath)
length = int(input_movie.get(cv2.cap_prop_frame_count))
 
#设置output
output_movie = cv2.videowriter(input_filepath.replace("mp4","avi").replace("input","output"), cv2.videowriter_fourcc('d', 'i', 'v', 'x'), 25, (1280, 720))
 
# initialize some variables
frame_number = 0
 
while true:
 # grab a single frame of video
 ret, frame = input_movie.read()
 
 frame_number += 1
 
 # quit when the input video file ends
 if not ret:
  break
 
 # draw a box around the body: input the top left point(x,y) and bottom right point(x,y)
 #cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
 
 # write the resulting image to the output video file
 print("writing frame {} / {}".format(frame_number, length))
 output_movie.write(frame)
 
# all done!
input_movie.release()
cv2.destroyallwindows()

以上这篇python对视频画框标记后保存的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。