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实现TCP协议下的端口映射功能的脚本程序示例

Python实现TCP协议下的端口映射功能的脚本程序示例

1 端口映射 举个例子来说明一下端口映射的作用。 有A、B、C三台计算机,A、B互通,B、C互通,但是A、C不通,这个时候在C上开了一个Web服务,如何让A访问C的Web服务? 最简单有...

django的聚合函数和aggregate、annotate方法使用详解

支持聚合函数的方法: 提到聚合函数,首先我们要知道的就是这些聚合函数是不能在django中单独使用的,要想在django中使用这些聚合函数,就必须把这些聚合函数放到支持他们的方法内去执...

基于hashlib模块--加密(详解)

用于加密相关的操作,3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法 import hashl...

pytorch 实现将自己的图片数据处理成可以训练的图片类型

为了使用自己的图像数据,需要仿照pytorch数据输入创建新的类,其中数据格式为numpy.ndarray。 将自己的图片保存到numpy.ndarray中,然后创建类 from t...

Python matplotlib画图实例之绘制拥有彩条的图表

Python matplotlib画图实例之绘制拥有彩条的图表

生产定制一个彩条标签。 首先导入: import matplotlib.pyplot as plt import numpy as np from matplotlib import...