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封装shell命令实例分析

本文实例讲述了Python封装shell命令的方法。分享给大家供大家参考。具体实现方法如下: # -*- coding: utf-8 -*- import os import sub...

python多线程同步之文件读写控制

python多线程同步之文件读写控制

本文实例为大家分享了python多线程同步之文件读写控制的具体代码,供大家参考,具体内容如下 1、实现文件读写的文件ltz_schedule_times.py #! /usr/bin...

PyQt5 对图片进行缩放的实例

如下所示: def shrinkImage(self): ''' 缩小图片 :return: ''' scale = 0.8 #每次缩小20% img = QImage...

Python实现Youku视频批量下载功能

Python实现Youku视频批量下载功能

前段时间由于收集视频数据的需要,自己捣鼓了一个YouKu视频批量下载的程序。东西虽然简单,但还挺实用的,拿出来分享给大家。   版本:Python2.7+BeautifulSoup3.2...

浅析python3字符串格式化format()函数的简单用法

 format()函数 """ 测试 format()函数 """ def testFormat(): # format()函数中有几个元素,前面格式化的字符串中就要有...