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

相关文章

Python3 文章标题关键字提取的例子

Python3 文章标题关键字提取的例子

思路: 1.读取所有文章标题; 2.用“结巴分词”的工具包进行文章标题的词语分割; 3.用“sklearn”的工具包计算Tf-idf(词频-逆文档率); 4.得到满足关键词权重阈值的词...

python中global与nonlocal比较

python引用变量的顺序: 当前作用域局部变量->外层作用域变量->当前模块中的全局变量->python内置变量 一、global global关键字用来在函数或其他...

python 域名分析工具实现代码

代码如下: 复制代码 代码如下:import sys, urllib import datetime,time def getDate(): strday=datetime.dateti...

Pytorch Tensor基本数学运算详解

1. 加法运算 示例代码: import torch # 这两个Tensor加减乘除会对b自动进行Broadcasting a = torch.rand(3, 4) b = to...

Python编写合并字典并实现敏感目录的小脚本

0x00 起因 接触网安快一年了,爱收集一些字典啊敏感目录文件啊什么的。收集多了难免有重复,并且有的也需要合并使用方便。自己就写了一个小小的脚步用来完成这个目的。 0x01 代码 第...