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

yipeiwu_com6年前Python基础

需要画框取消注释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对视频画框标记后保存的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

修改Pandas的行或列的名字(重命名)

pandas.DataFrame.rename 使用函数: DataFrame.rename(mapper=None, index=None, colum...

Python实现高效求解素数代码实例

素数是编程中经常需要用到的。 作为学习Python的示例,下面是一个高效求解一个范围内的素数的程序,不需要使用除法或者求模运算。 #coding:utf-8 #设置python...

写了个监控nginx进程的Python脚本

复制代码 代码如下: #!/usr/bin/env python import os, sys, time while True: time.sleep(3) try: ret = os...

python随机数分布random测试

python随机数分布random测试

因为概率问题,所以需要测试一下python的随机数分布。到底是平均(均匀)分布,还是正态(高斯)分布。 测试代码如下: #! /usr/bin/env python #coding=...

在Django的模型和公用函数中使用惰性翻译对象

在模型和公用函数中,使用ugettext_lazy()和ungettext_lazy()来标记字符串是很普遍的操作。 当你在你的代码中其它地方使用这些对象时,你应当确定你不会意外地转换它...