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实现根据窗口标题调用窗口的方法。分享给大家供大家参考。具体分析如下: 当你知道一个windows窗口的标题后,可以用下面的代码调用窗口,甚至向窗口内写入内容。...

Python3.5编程实现修改IIS WEB.CONFIG的方法示例

本文实例讲述了Python3.5编程实现修改IIS WEB.CONFIG的方法。分享给大家供大家参考,具体如下: #!/usr/bin/env python3.5 # -*- cod...

浅谈对yield的初步理解

如下所示: def go(): while True: data = 1 r = yield data # data是返回值,r是接收值 print("d...

Python closure闭包解释及其注意点详解

Python closure闭包解释及其注意点详解

一、闭包 1.定义:当一个函数在内部定义函数,并且内部的函数应用外部函数的参数或者局部变量,当内部函数被当做返回值的时候,相关参数和变量保存在返回的函数之中,这种结果,叫做闭包。 2.例...

Django管理员账号和密码忘记的完美解决方法

Django管理员账号和密码忘记的完美解决方法

发现问题 看着Django的教程学习搭建网站,结果忘记第一次创建的账号和密码了。结果搭建成功以后,一直无法登陆到管理页面,进行不下去了。 如图所示: 在网上找了很多的方法都不行,最后使...