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 numpy 矩阵堆叠实例

在实际操作中,遇到了矩阵堆叠的操作,本来想着自己写一个函数,后来想,应该有库函数,于是一阵找寻 import numpy as np a = np.array([1,2,3]) b...

Python数据类型之Tuple元组实例详解

本文实例讲述了Python数据类型之Tuple元组。分享给大家供大家参考,具体如下: tuple元组 1.概述 本质上是一种有序的集合,和列表非常的相似,列表使用[]表示,元组使用()表...

Python中使用PIPE操作Linux管道

Python中使用PIPE操作Linux管道

Linux中进程的通信方式有信号,管道,共享内存,消息队列socket等。其中管道是*nix系统进程间通信的最古老形式,所有*nix都提供这种通信方式。管道是一种半双工的通信机制,也就是...

使用pandas对矢量化数据进行替换处理的方法

使用pandas处理向量化的数据,进行数据的替换时不仅仅能够进行字符串的替换也能够处理数字。 做简单的示例如下: In [4]: data = Series(range(5))...

python 生成目录树及显示文件大小的代码

python 生成目录树及显示文件大小的代码

比如 1--1      2--1           2    &nbs...