Efficient Background subtraction with OpenCV

后端 未结 2 834
渐次进展
渐次进展 2020-12-07 19:28

I want to do background subtraction in a video file using OpenCV method. Right now I\'m able to do background subtraction, but the problem is that I couldn\'t get the output

相关标签:
2条回答
  • 2020-12-07 20:12

    Okay, I don't understand how TempFrame (your foreground) could be greyscale if you are using background subtraction. You must be using a very special algorithm. But assuming TempFrame is greyscale, then you would do this:

    cv::Mat mask = tempFrame > 0.5;
    
    cv::Mat outFrame;
    capturedFrame.copyTo(outFrame, mask);
    

    That is OpenCV 2.0 code above. The number 0.5 is a threshold, you'll need to set it to something appropriate. If you're not using floating-point images, you'd probably set it to 128 or something like that. This is the same thing in OpenCV 1.1 code:

    CvMat* mask = cvCreateMat(tempFrame.rows, tempFrame.cols, CV_8UC1);
    cvCmpS(tempFrame, 0.5, mask);
    
    CvMat* outFrame = cvCreateMat(capturedFrame.rows, capturedFrames.cols, CV_32FC3);
    cvCopy(capturedFrame, outFrame, mask);
    
    0 讨论(0)
  • 2020-12-07 20:18

    http://vimeo.com/27477093

    code is here

    http://code.google.com/p/derin-deli-mavi/downloads/detail?name=denemeOpenCv23.zip&can=2&q=

    to reach a colored foreground just copy image by using foreground mask

    // image.copyTo(foreground,foreground);

    0 讨论(0)
提交回复
热议问题