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设计】。

相关文章

Python中文竖排显示的方法

本文实例讲述了Python中文竖排显示的方法。分享给大家供大家参考。具体如下: 这里将中文竖排显示 比如 衣食者人之生利也,然且犹尚有节,葬埋者人之死利也,夫何独无节於此乎 输出为: 衣...

python获取android设备的GPS信息脚本分享

在android上,我们可以使用QPython来编写、执行Python脚本。它对很多android 系统函数进行了方便的封装,使用QPython编写功能简单的小程序异常方便。 这个示例是...

Python cookbook(数据结构与算法)实现优先级队列的方法示例

本文实例讲述了Python实现优先级队列的方法。分享给大家供大家参考,具体如下: 问题:要实现一个队列,它能够以给定的优先级对元素排序,且每次pop操作时都会返回优先级最高的那个元素;...

在Python中使用M2Crypto模块实现AES加密的教程

 AES(英文:Advanced Encryption Standard,中文:高级加密标准),是一种区块加密标准。AES将原始数据分成多个4×4字节矩阵来处理,通过预先定义的...

Python中的多行注释文档编写风格汇总

Python中的多行注释文档编写风格汇总

什么是docstring 在软件工程中,其实编码所占的部分是非常小的,大多是其它的事情,比如写文档。文档是沟通的工具。 在Python中,比较推崇在代码中写文档,代码即文档,比较方便,...