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对于requests的封装方法详解

由于requests是http类接口的核心,因此封装前考虑问题比较多: 1. 对多种接口类型的支持; 2. 连接异常时能够重连; 3. 并发处理的选择; 4. 使用方便,容易维护; 当前...

Python字符串格式化输出方法分析

本文实例分析了Python字符串格式化输出方法。分享给大家供大家参考,具体如下: 我们格式化构建字符串可以有3种方法: 1 元组占位符 m = 'python' astr = 'i...

Django使用uwsgi部署时的配置以及django日志文件的处理方法

首先保证你有一个可运行的django工程 然后在虚拟环境里面安装好uwsgi pip install uwsgi 配置nginx的服务如下 server {...

Python第三方Window模块文件的几种安装方法

Python第三方Window模块文件的几种安装方法

python安装第三方模块 使用软件管理工具pip python自带了包管理工具,就像手机app商城,91助手等软件的功能一样。 python2与python3安装模块的方法相似,值得注...

django基于存储在前端的token用户认证解析

django基于存储在前端的token用户认证解析

一.前提 首先是这个代码基于前后端分离的API,我们用了django的framework模块,帮助我们快速的编写restful规则的接口 前端token原理: 把(token=加密后的...