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 log模块logging记录打印用法解析

这篇文章主要介绍了Python log模块logging记录打印用法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 日志基础教程...

Python实现列表转换成字典数据结构的方法

本文实例讲述了Python实现列表转换成字典数据结构的方法。分享给大家供大家参考,具体如下: ''' [ {'symbol': 101, 'sort': 1, 'name': '...

对python 数据处理中的LabelEncoder 和 OneHotEncoder详解

如下所示: #简单来说 LabelEncoder 是对不连续的数字或者文本进行编号 from sklearn.preprocessing import LabelEncoder le...

动态创建类实例代码

例如: import mymodule myobject = mymodule.myclass() 或者 from mymodule import myclass myobject =...

pycharm使用matplotlib.pyplot不显示图形的解决方法

如下案例,可以正常保存图像,但是plt.show()不能正常显示图像,这里是使用pandas模块读取csv文件: # coding=utf-8 import pandas as pd...