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 Django框架防御CSRF攻击的方法分析

本文实例讲述了Python Django框架防御CSRF攻击的方法。分享给大家供大家参考,具体如下: 项目名/settings.py(项目配置,csrf中间件配置): MIDDLEW...

PyCharm的设置方法和第一个Python程序的建立

PyCharm的设置方法和第一个Python程序的建立

1.代码编辑 字体大小设置 进入 File—》Settings—》Editor—》Colors & Fonts—》Font中。 首先要点击“Save as”然后为这个设置命名,我这里填入...

Python 正则表达式(转义问题)

先说一个比较囧的事情:在写虾米音乐试听下载器的时候遇到一个问题,因为保存的文件都是用音乐的标题命名的,所以碰到一些诸如「対峙/out border」等含有非法字符(哼哼,说的就是你 →_...

Python中django学习心得

Python中django学习心得

以下是作者在学习Python中django框架时的学习笔记,并把测试的代码做了详细分析,最后还附上了学习心得,值得大家学习。 URL配置(URLconf)就像Django 所支撑网站的目...

推荐下python/ironpython:从入门到精通

最近无聊,下了个visual studio 2005的furture,发现里面多了对动态语言的支持.其实很早就想摆弄下python,正好是个机会.一开始是想学ironpython,但后来...