gpt4 book ai didi

OpenCV - 在背景减法器 MOG 中修复前景

转载 作者:太空宇宙 更新时间:2023-11-03 22:51:08 26 4
gpt4 key购买 nike

我们如何在 opencv-python 中使用 mog 背景减法器修复前景?我正在尝试拥有一个更稳定的前景,一旦它可以正确地从背景中减去前景(例如将前景固定大约 5 秒),它就可以继续显示前景这是我的代码:

cap = cv2.VideoCapture(0)
history = 500 # or whatever you want it to be
accelerate = 5

fgbg = cv2.createBackgroundSubtractorMOG2(history=500, varThreshold=20, detectShadows=True)

count=0
while(1):
for i in (1, accelerate):
ret, frame = cap.read()
fgmask = fgbg.apply(frame, learningRate=1.0/history)
imageproc(fgmask,count)

# time.sleep(5)
k = cv2.waitKey(0) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()

最佳答案

import numpy as np
import cv2
import time

cap = cv2.VideoCapture('video.avi')

fgbg = cv2.createBackgroundSubtractorMOG()
while(1):
ret, frame = cap.read()

fgmask = fgbg.apply(frame)

cv2.imshow('frame',fgmask)
time.sleep(5)
k = cv2.waitKey(30) & 0xff
if k == 27:
break

cap.release()
cv2.destroyAllWindows()

关于OpenCV - 在背景减法器 MOG 中修复前景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37339973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com