opencv背景减法得到颜色对象

opencv background subtraction get color objects

我用下面的教程做了背景减法, http://docs.opencv.org/master/d1/dc5/tutorial_background_subtraction.html#gsc.tab=0

但使用pMOG2->apply( frame, fgMaskMOG2 )方法return输出为二值图像。

有没有什么方法可以去除背景后只得到彩色对象或者使用二值图像得到彩色图像?

您可以做的一件事是使用二值图像作为遮罩,将彩色图像中的对象复制到另一个图像中:

// create an image like frame but initialized to zeros
cv::Mat colorForeground = cv::Mat::zeros(frame.size(), frame.type()); 
// copy color objects into the new image using mask
frame.copyTo(colorForeground, fgMaskMOG2); 

现在,在 colorForeground 中,您可以看到彩色对象。