Ask Your Question
0

opencv background subtraction

asked 2014-04-08 05:44:21 -0600

updated 2014-04-08 05:57:35 -0600

berak gravatar image

I am working on a hand gesture recognition problem, when I try to extract the foreground bu subtraction of the still background the object appears to be transparent. Why? Please help and suggest any better approach to detection of foreground. Thank you.

edit retag flag offensive close merge delete

Comments

>>> bgs = cv2.BackgroundSubtractorMOG2()

>>> help(bgs)

berak gravatar imageberak ( 2014-04-08 06:26:28 -0600 )edit

Are you using findContours or Canny? When you say transparent, do you mean nothing there or a ghostly set of lines?

Will Stewart gravatar imageWill Stewart ( 2014-04-09 09:29:32 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-08-08 20:51:23 -0600

Sinan gravatar image

I slightly changed the code i've found from some website that i do not remember anymore.

#include <opencv2/opencv.hpp>
#include <iostream>
#include <vector>

int main ()
{
  cv::Mat frame;
  cv::Mat back;
  cv::Mat fore;
  cv::VideoCapture cap (0);
  cv::BackgroundSubtractorMOG2 bg;
  bg.set ("nmixtures", 3);
  bg.setBool("detectShadows", false);

  std::vector < std::vector < cv::Point > >contours;

    cv::namedWindow("Frame");
    cv::namedWindow("Background");

    for(;;)
    {
        cap >> frame;
        bg.operator ()(frame,fore);
        bg.getBackgroundImage(back);
        cv::erode(fore,fore,cv::Mat());
        cv::dilate(fore,fore,cv::Mat());
        cv::findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
        cv::drawContours(frame,contours,-1,cv::Scalar(0,0,255),2);
        cv::imshow("Frame",frame);
        cv::imshow("Background",back);
        if(cv::waitKey(30) >= 0) break;
    }
    return 0;
}
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-04-08 05:44:21 -0600

Seen: 404 times

Last updated: Aug 08 '14