2013-04-21 50 views
1

我正在處理一個視頻處理項目,該項目將攝像頭饋送作爲輸入並獲得靜態背景。我不需要像openSv中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) 
     ); 
    } 

但問題是我沒有得到正確的前景。無論如何,無論背景的複雜性和其他因素如何,我​​都可以改進前景生成,並始終使用一些矩形邊界框來限定前景對象。

回答

0

有很多簡單和複雜的方法來做到這一點。採用像素明智的概率方法是絕對值得推薦的。您還可以在外觀上使用像馬爾可夫模型這樣的東西來優化結果。請參閱this paper,特別是相關工作部分以及它們精修前景對象的最後一個位。