carolinepacheco / lbp-library

LBP Library - A Collection of LBP algorithms for background subtraction in videos.
MIT License
112 stars 38 forks source link

How to use this library to model background? #8

Open jackyfriend opened 5 years ago

jackyfriend commented 5 years ago

Hello, this library is just a lbp-like descriptors, but I want to know how to use them to update backgrounds? How to use them together with KDE or MoG? Thank you!

andrewssobral commented 5 years ago

Hello @jackyfriend , We are sorry for our delayed feedback to you. Yes, this library can be easily integrated with the bgslibrary for background-foreground separation. You need:

  1. First, capture the frame and apply the desired LBP descriptor to the input image (frame)
  2. Get the texture image (the output image of the LBP descriptor) and use it as input image of your desired background subtraction algorithm. You can do it with any background subtraction algorithm of the bgslibrary. Please, let us know if it's clear for you.
andrewssobral commented 5 years ago

@jackyfriend just a bit of code to show you an example: References: https://github.com/andrewssobral/bgslibrary/blob/master/Demo.cpp https://github.com/carolinepacheco/lbplibrary/blob/master/Main.cpp

...
LBP *lbp;
lbp = new XCSLBP;

while (key != 's')
{
  // Capture frame-by-frame
  capture >> img_input;
  frame_counter += 1;

  if (img_input.empty()) break;

  cv::imshow("input", img_input);

  cv::Mat img_gray;
  cv::cvtColor(img_input, img_gray, CV_BGR2GRAY);
  imshow("gray", img_gray);

  cv::Mat img_lbp;
  lbp->run(img_gray, img_lbp);
  cv::normalize(img_lbp, img_lbp, 0, 255, cv::NORM_MINMAX, CV_8UC1);
  cv::imshow("lbp", img_lbp);

  cv::Mat img_mask;
  cv::Mat img_bkgmodel;
  try
  {
    // use `img_lbp` instead of `img_input`
    bgs->process(img_lbp, img_mask, img_bkgmodel); // by default, it shows automatically the foreground mask image

    //if(!img_mask.empty())
    //  cv::imshow("Foreground", img_mask);
    //  do something
  }
  catch (std::exception& e)
  {
    std::cout << "Exception occurred" << std::endl;
    std::cout << e.what() << std::endl;
  }

  key = cv::waitKey(33);
}
delete lbp;
...