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

yipeiwu_com5年前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对dataFrame中某一个列的数据进行处理的方法

背景:dataFrame的数据,想对某一个列做逻辑处理,生成新的列,或覆盖原有列的值 下面例子中的df均为pandas.DataFrame()的数据 1、增加新列,或更改某列的值 d...

Python面向对象程序设计之私有属性及私有方法示例

本文实例讲述了Python面向对象程序设计之私有属性及私有方法。分享给大家供大家参考,具体如下: 如果有一个对象,当需要对其进行修改属性时,有2种方法: (1)对象名.属性名=数据---...

Django中使用locals()函数的技巧

对 current_datetime 的一次赋值操作: def current_datetime(request): now = datetime.datetime.now()...

通过pykafka接收Kafka消息队列的方法

没有Kafka环境,所以也没有进行验证。感觉今后应该能用到,所以借抄在此,备查。 pykafka使用示例,自动消费最新消息,不重复消费: # -* coding:utf8 *- fr...

Django卸载之后重新安装的方法

前言 大家应该都有所体会,在不同的项目可能会使用不同的Django版本,兼任性是大问题,如果不幸要去接手不同版本的项目,比较惨烈! 如果想重装一个Django版本,需要先卸载后安装。...