C++ 从视频流中提取前景

C++ 从视频流中提取前景,c++,opencv,image-processing,background-subtraction,C++,Opencv,Image Processing,Background Subtraction,我正在从事一个视频处理项目,该项目以摄像头为输入,有一个静态背景。我不需要像opencv中的BackgroundSubtractorMOG那样生成任何类型的动态背景。我正在尝试将前景对象绑定到边界框中。所以这就是我所做的 cv::absdiff(back_frame,matProcessed,temp); //back_frame is the background matProcessed is the frame from CAMERA in grayscale cv::th

我正在从事一个视频处理项目,该项目以摄像头为输入,有一个静态背景。我不需要像opencv中的BackgroundSubtractorMOG那样生成任何类型的动态背景。我正在尝试将前景对象绑定到边界框中。所以这就是我所做的

cv::absdiff(back_frame,matProcessed,temp);         //back_frame is the background matProcessed is the frame from CAMERA in grayscale
cv::threshold(temp,temp,20,255,THRESH_BINARY);

cv::findContours(temp,contours,CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
std::vector<Rect> boundRect( contours.size() );
std::vector< std::vector<Point> > contours_poly( contours.size() );

int j=0;
for(int i = 0; i < contours.size(); i++ )
{
           if(contourArea(contours[i])>100)
           {
               approxPolyDP( Mat(contours[i]), contours_poly[i], 10, true );
               boundRect[j] = boundingRect( Mat(contours_poly[i]) );
               j++;
           }


 }
 cv::rect r;
   for (int i = 0; i < boundRect.size(); i++)
    {
        r = boundRect[i];

        cv::rectangle(
            frame,
            cv::Point(r.x, r.y),
            cv::Point(r.x + r.width, r.y + r.height),
            CV_RGB(0,255,0)
        );
    }
cv::absdiff(后帧、matProcessed、temp)//back_frame是背景,它是来自摄影机的灰度帧
cv::阈值(温度、温度、20255、阈值);
cv::findContours(温度、轮廓、cv_-RETR_外部、cv_-CHAIN_近似、简单、点(0,0));
std::vector boundRect(contours.size());
std::vector等高线_poly(等高线.size());
int j=0;
对于(int i=0;i100)
{
approxPolyDP(Mat(等高线[i]),等高线[i],10,真);
boundRect[j]=boundingRect(Mat(等高线_poly[i]);
j++;
}
}
cv::rect r;
对于(int i=0;i

但问题是我没有正确地看到前景。无论如何,我都可以改进前景生成,并始终使用一些矩形边界框来绑定前景对象,而不考虑背景复杂度和其他因素???

有各种简单和复杂的方法来实现这一点。绝对推荐使用像素级概率方法。您还可以在外观上使用马尔可夫模型之类的东西来优化结果。具体请参阅相关工作部分和最后一位,它们在其中细化前景对象