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

相关文章

python实现井字棋游戏

本文实例介绍了python实现井字棋游戏的方法,分享给大家,具体内容如下 windows7下python3.4.0编译运行通过。由于采用了cmd调用,所以与Linux不兼容,无法在Lin...

Python迭代用法实例教程

本文实例讲述了Python中迭代的用法,是一个非常实用的技巧。分享给大家供大家参考借鉴之用。具体分析如下: 如果给定一个list或tuple,我们可以通过for循环来遍历这个list或t...

Python有序字典简单实现方法示例

Python有序字典简单实现方法示例

本文实例讲述了Python有序字典简单实现方法。分享给大家供大家参考,具体如下: 代码: # -*- coding: UTF-8 -*- import collections pri...

Python2中文处理纪要的实现方法

python2不是以unicode作为基本代码字符类型,碰到乱码的几率是远远高于python3,但即便如此,相信很多人,也不想随意的迁移到python3,这里就总结几个我平常碰到的问题及...

python中argparse模块用法实例详解

本文实例讲述了python中argparse模块用法。分享给大家供大家参考。具体分析如下: 平常在写命令行工具的时候,经常会带参数,所以用python中的argparse来实现。 #...