具体内容用的时候再看,目前先做个标记
import numpy as npimport cv2 from time import sleep import queueclass MHI:def __init__(self,cap,tau,delta,xi,t):self.tau=tauself.delta=deltaself.xi=xiself.t=tself.cap=capself.data = queue.Queue()ret,frame=cap.read()if ret:for i in range(t):self.data.put(frame)self.H = np.zeros(frame.shape) def getimag(self): ret,frame=cap.read()if not ret:return ret,frameself.data.put(frame)old_frame=self.data.get() a=cv2.addWeighted(old_frame.astype(float),1, frame.astype(float), -1, 0)D= np.fabs(a)Psi= D >=self.xi c=self.H-self.deltaH=np.maximum(0,c) H[Psi]=self.tauself.H=Hreturn ret, H.astype("uint8")cap = cv2.VideoCapture(0) # a=MHI(cap,tau=200,xi=20,delta=10,t=1)while cap.isOpened():_,frame=a.getimag()cv2.imshow("out_win", frame)sleep(0.04)if cv2.waitKey(1) == ord('q'):breakcap.release()cv2.destroyAllWindows()
如果觉得《人体轮廓特征—运动历史图—python实现》对你有帮助,请点赞、收藏,并留下你的观点哦!