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使用Turtle库绘制一棵西兰花

Turtle库是Python中一个强大的绘制图像的函数库,灵活使用Turtle库可以绘制各种好看的图像。 下面介绍使用Turtle库绘制一棵西兰花。 绘制一棵西兰花,从主干出发以一定的角...

python中使用OpenCV进行人脸检测的例子

OpenCV的人脸检测功能在一般场合还是不错的。而ubuntu正好提供了python-opencv这个包,用它可以方便地实现人脸检测的代码。 写代码之前应该先安装python-openc...

Python面向对象基础入门之编码细节与注意事项

前言 在前面,我用了3篇文章解释python的面向对象: 面向对象:从代码复用开始 面向对象:设置对象属性 类和对象的名称空间 本篇是第4篇,用一个完整的示例来解释面向对...

Python对象体系深入分析

Python对象体系深入分析

本文较为详细的分析了了Python的对象体系。分享给大家供大家参考。具体如下: Guido用C语言创造了Python,在Python的世界中一切皆为对象. 一.C视角中的Python对象...

Linux下python3.6.1环境配置教程

Linux下python3.6.1环境配置教程

linux系统环境自带python2.6,但有时我们项目使用的版本可能是3.x以上等等,此时我们需要在linux中再安装项目所需的python版本,此时就涉及多版本共存问题了,很多同学在...