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连接oracle数据库实例

本文实例讲述了python连接oracle数据库的方法,分享给大家供大家参考。具体步骤如下: 一、首先下载驱动:(cx_Oracle) http://www.python.net/cre...

使用python opencv对目录下图片进行去重的方法

版本: 平台:ubuntu 14 / I5 / 4G内存 python版本:python2.7 opencv版本:2.13.4 依赖: 如果系统没有python,则需要进行安装 sudo...

pycharm 使用心得(一)安装和首次使用

pycharm 使用心得(一)安装和首次使用

首先预览一下 PyCharm 在实际应用中的界面:(更改了PyCharm的默认风格) 安装 首先去下载最新的pycharm 2.7.3,进行安装。可以直接在官网下载。 PyCharm...

Python多进程并发(multiprocessing)用法实例详解

本文实例讲述了Python多进程并发(multiprocessing)用法。分享给大家供大家参考。具体分析如下: 由于Python设计的限制(我说的是咱们常用的CPython)。最多只能...

python sorted函数的小练习及解答

前两天学习了一下socket编程,在向某大神请教问题时被嫌弃了,有一种还没学会走就想跑的感觉。大神说我现在的水平应该去做一些像是操作文件、序列号等的小练习来加深理解。下面是他给我出的小练...