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

相关文章

对numpy中数组元素的统一赋值实例

Numpy中的数组整体处理赋值操作一直让我有点迷糊,很多时候理解的不深入。今天单独列写相关的知识点,进行总结一下。 先看两个代码片小例子: 例子1: In [2]: arr =np....

Django框架中间件定义与使用方法案例分析

Django框架中间件定义与使用方法案例分析

本文实例讲述了Django框架中间件定义与使用方法。分享给大家供大家参考,具体如下: 1. 定义 Django中的中间件是一个轻量级、底层的插件系统,可以介入Django的请求和响应处理...

Django框架中间件(Middleware)用法实例分析

Django框架中间件(Middleware)用法实例分析

本文实例讲述了Django框架中间件(Middleware)用法。分享给大家供大家参考,具体如下: 1、面向切面编程 切点(钩子) 切点允许我们动态的在原有逻辑中插入一部分代码...

Python 实现try重新执行

Python try重新执行: def numberinput(): #创建方法 try: s=int(input('number:')) return s...

Python 编程速成(推荐)

Python是一种非常流行的脚本语言,而且功能非常强大,几乎可以做任何事情,比如爬虫、网络工具、科学计算、树莓派、Web开发、游戏等各方面都可以派上用场。同时无论在哪种平台上,都可以用...