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

相关文章

2018年Python值得关注的开源库、工具和开发者(总结篇)

2018年Python值得关注的开源库、工具和开发者(总结篇)

1、开源库 Web 领域:Sanic  https://github.com/channelcat/sanic 这个库的名字和之前一个很火的梗有关,有人在 youtube...

Python实现根据IP地址和子网掩码算出网段的方法

本文实例讲述了Python实现根据IP地址和子网掩码算出网段的方法。分享给大家供大家参考。具体如下: 该代码在Linux环境2.6.6python版本测试通过! #!/usr/bin...

讲解Python中for循环下的索引变量的作用域

我们从一个测试开始。下面这个函数的功能是什么?   def foo(lst): a = 0 for i in lst: a += i b = 1...

使用tensorflow实现线性回归

使用tensorflow实现线性回归

本文实例为大家分享了tensorflow实现线性回归的具体代码,供大家参考,具体内容如下 一、随机生成1000个点,分布在y=0.1x+0.3直线周围,并画出来 import ten...

python 容器总结整理

python 容器总结整理 list 可变数组 tuple 不可变数组 dict 键值对(key-value)的字典(dictionary) 初始化: a={‘lyt':90}...