代码拉取完成,页面将自动刷新
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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。