opencv背景减法获取颜色对象 [英] opencv background subtraction get color objects
问题描述
我已经使用下面的教程进行背景扣除, http://docs.opencv.org/master/d1 /dc5/tutorial_background_subtraction.html#gsc.tab=0
I've used below tutorial to do background subtraction, http://docs.opencv.org/master/d1/dc5/tutorial_background_subtraction.html#gsc.tab=0
但是使用pMOG2->apply( frame, fgMaskMOG2 )
方法将输出作为二进制图像返回.
But using pMOG2->apply( frame, fgMaskMOG2 )
method return output as a binary image.
有什么方法可以在去除背景后仅获取彩色对象或使用二进制图像获取彩色图像?
Is there any method to get only color objects after removing the background or get color image using binary image?
推荐答案
您可以做的一件事是使用二进制图像作为蒙版,将对象从彩色图像复制到另一图像:
One thing you can do is to use the binary image as a mask for coping the objects from the color image into another image:
// 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
中,您可以看到彩色的对象.
Now, in colorForeground
, you can see the objects in color.
这篇关于opencv背景减法获取颜色对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!