1 Star 0 Fork 0

pguanhai/bgslibrary

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
demo.py 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
Andrews Sobral 提交于 2019-08-15 21:30 . renamed python module
import numpy as np
import cv2
import pybgs as bgs
algorithm = bgs.FrameDifference()
video_file = "dataset/video.avi"
capture = cv2.VideoCapture(video_file)
while not capture.isOpened():
capture = cv2.VideoCapture(video_file)
cv2.waitKey(1000)
print("Wait for the header")
#pos_frame = capture.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
#pos_frame = capture.get(cv2.CV_CAP_PROP_POS_FRAMES)
pos_frame = capture.get(1)
while True:
flag, frame = capture.read()
if flag:
cv2.imshow('video', frame)
#pos_frame = capture.get(cv2.cv.CV_CAP_PROP_POS_FRAMES)
#pos_frame = capture.get(cv2.CV_CAP_PROP_POS_FRAMES)
pos_frame = capture.get(1)
#print str(pos_frame)+" frames"
img_output = algorithm.apply(frame)
img_bgmodel = algorithm.getBackgroundModel()
cv2.imshow('img_output', img_output)
cv2.imshow('img_bgmodel', img_bgmodel)
else:
#capture.set(cv2.cv.CV_CAP_PROP_POS_FRAMES, pos_frame-1)
#capture.set(cv2.CV_CAP_PROP_POS_FRAMES, pos_frame-1)
#capture.set(1, pos_frame-1)
#print "Frame is not ready"
cv2.waitKey(1000)
break
if 0xFF & cv2.waitKey(10) == 27:
break
#if capture.get(cv2.cv.CV_CAP_PROP_POS_FRAMES) == capture.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT):
#if capture.get(cv2.CV_CAP_PROP_POS_FRAMES) == capture.get(cv2.CV_CAP_PROP_FRAME_COUNT):
#if capture.get(1) == capture.get(cv2.CV_CAP_PROP_FRAME_COUNT):
#break
cv2.destroyAllWindows()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/pguanhai/bgslibrary.git
git@gitee.com:pguanhai/bgslibrary.git
pguanhai
bgslibrary
bgslibrary
master

搜索帮助