图像背景分割

1、OpenCV背景分割

  1. MOG算法,即高斯混合模型分离算法,全称Gaussian Mixture-based Background/Foreground Segmentation Algorithm。2001年,由P.KadewTraKuPong和R.Bowden在论文“An improved adaptive background mixture model for real-time tracking with shadow detection”中提出。它使用一种通过K高斯分布的混合来对每个背景像素进行建模的方法(K = 3〜5)。
bs = cv2.bgsegm.createBackgroundSubtractorMOG(history=history)
bs.setHistory(history)

fg_mask = bs.apply(frame)  

  1. MOG2算法,也是高斯混合模型分离算法,是MOG的改进算法。它基于Z.Zivkovic发布的两篇论文,即2004年发布的“Improved adaptive Gausian mixture model for background subtraction”和2006年发布的“Efficient Adaptive Density Estimation per Image Pixel for the Task of Background Subtraction”中提出。该算法的一个重要特征是 它为每个像素选择适当数量的高斯分布,它可以更好地适应不同场景的照明变化等。
bs = cv2.createBackgroundSubtractorMOG2(history=history, detectShadows=True)
bs.setHistory(history)

fg_mask = bs.apply(frame) 

  1. GMG

该算法结合统计背景图像估计和每像素贝叶斯分割。由 Andrew B. Godbehere, Akihiro Matsukawa, Ken Goldberg在2012年的文章“Visual Tracking of Human Visitors under Variable-Lighting Conditions for a Responsive Audio Art Installation”中提出。该算法使用前几个(默认为120)帧进行后台建模。它采用概率前景分割算法,使用贝叶斯推理识别可能的前景对象。

bs = cv2.bgsegm.createBackgroundSubtractorGMG(initializationFrames=history)

fg_mask = bs.apply(frame) 
  1. KNN

KNN算法,即K-nearest neigbours - based Background/Foreground Segmentation Algorithm。2006年,由Zoran Zivkovic 和Ferdinand van der Heijden在论文"Efficient adaptive density estimation per image pixel for the task of background subtraction."中提出。

bs = cv2.createBackgroundSubtractorKNN(detectShadows=True)

fg_mask = bs.apply(frame)  

参考:

猜你喜欢

转载自blog.csdn.net/zml194849/article/details/123043920