Giter VIP home page Giter VIP logo

backgroundsplit-opencv's Introduction

This repository is the C++ Source Code of several algorithms of Extracting Background, which are based on OpenCV libraries after I learn about the theory of these algorithms. These Extracting Background Algorithms includes Frame-Difference Algorithm, Background-Difference Algorithm, ViBe Algorithm, ViBe+ Algorithm.

Extracting Background Algorithms' Theory

I wrote a blog about these algorithms' theory. And here is the web address:
《背景提取算法——帧间差分法、背景差分法、ViBe背景提取算法》
《论文翻译:ViBe+算法(ViBe算法的改进版本)》
The Paper of ViBe+ Algorithm's web address:
《Background Subtraction: Experiments and Improvements for ViBe》

Files Introduction

  • src - Source Codes' Path
    • FramesDifference - source codes of Frame-Difference Algorithm
    • BGDifference - source codes of Background-Difference Algorithm
    • ViBe - source codes of ViBe Algorithm
    • ViBe+ - source codes of ViBe+ Algorithm
  • Image - the Path of Screenshot of Test Programs
  • Video - the Path of Test Video
  • CMakeLists.txt - CMake File of this Project

Tutorial for Generating this Project

1. My Working Environment

  • Operating System: Ubuntu 14.04 LTS
  • Conditions before your cmake command:
    • have already done OpenCV's make & make install
    • have already done CMake's make & make install

Besides, I also wrote the tutorial blog of how to install OpenCV 2.4.9 in Ubuntu 14.04. Here are the websites:
CSDN:http://blog.csdn.net/ajianyingxiaoqinghan/article/details/62424132
GitHub:upcAutoLang/Blog#1

2. CMake this Project

Open a terminal and enter in the path of folder named GLCM_OpenCV, then input commands like below:

cmake ./
make

Then you will build this project.

The path of binary files - /BackgroundSplit-OpenCV/build/bin The path of library files - /BackgroundSplit-OpenCV/build/lib

Test Results

I run these 3 kinds of Algorithms by using video whose path is /BackgroundSplit-OpenCV/Video/Camera Road 01.avi, and 3 kinds of Algorithms' results are like below: the result of Frame-Difference Algorithm:
the result of Background-Difference Algorithm: the result of ViBe Algorithm: the result of ViBe+ Algorithm:

P.S: **1. Efficiency of ViBe Algorithm: **
the result of Debug Version:

Time of Update ViBe Background: 15.5914ms
Time of Update ViBe Background: 15.7827ms
Time of Update ViBe Background: 15.2309ms
Time of Update ViBe Background: 15.3791ms
Time of Update ViBe Background: 16.5063ms
Time of Update ViBe Background: 16.0289ms

the result of Release Version:

Time of Update ViBe Background: 3.88142ms
Time of Update ViBe Background: 3.71257ms
Time of Update ViBe Background: 3.59945ms
Time of Update ViBe Background: 3.35824ms
Time of Update ViBe Background: 3.57153ms
Time of Update ViBe Background: 3.44415ms

**2. Efficiency of ViBe+ Algorithm: **
the result of Debug Version:

Time of Update ViBe+ Background: 224.118ms
Time of Update ViBe+ Background: 222.495ms
Time of Update ViBe+ Background: 223.623ms
Time of Update ViBe+ Background: 243.826ms
Time of Update ViBe+ Background: 224.687ms
Time of Update ViBe+ Background: 223.875ms

the result of Release Version:

Time of Update ViBe+ Background: 66.9405ms
Time of Update ViBe+ Background: 67.1447ms
Time of Update ViBe+ Background: 69.6733ms
Time of Update ViBe+ Background: 68.3159ms
Time of Update ViBe+ Background: 67.0427ms
Time of Update ViBe+ Background: 75.1574ms
Time of Update ViBe+ Background: 68.5131ms

It shows that the amount of calculation increased and the efficiency of calculation decreased after increasing algorithm's complexity.

backgroundsplit-opencv's People

Contributors

upcautolang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

backgroundsplit-opencv's Issues

How to make the release version?

When I cmake&make it,the test program just Time of Update ViBe+ Background: 256.704ms.
How can I make the release version to make it faster?

Line 274 Maybe should be changed.

原代码:samples[i][j][random]=img.at(i, j);

由于此处为了更改邻居点的样本值,所以也许应该改成:
samples[row][col][random] = img.at (i, j);

A mistake in ViBe destructor

In ViBe::init(), a 3d array is applied, but it's released in a wrong way.
void ViBe::deleteSamples() { delete samples; }
It doesn't matter if ViBe.init() is just used once. But in the case where background should be built for many times, the program will crash due to a lack of memory.

The right way is to release the pointers one by one with the opposite order of applying for arrays.

the code which in vibe.cpp miss a "}" symbol

When using the developer's vibe project code, I found an error in the file which called "vibe.cpp". In line 53, “if” statement is missing "}" symbol, it will cause the compilation to fail. when i add "}" and it's ok. This question is too small, I will not pull request. You can close it ,when you see my issues. Any way , thank you very much.

memory leak in ViBe+

we should delete as follows
void ViBePlus::deleteSamples()
{

for(int i = 0; i <Gray.rows; ++i)
{
    for(int j = 0; j<Gray.cols; ++j)
    {
        for (int k = 0; k < num_samples + 1; k++)
        {
            delete []samples_Frame[i][j][k];
            samples_Frame[i][j][k] = nullptr;
        }
        delete []samples_Frame[i][j];
        delete []samples[i][j];

        samples_Frame[i][j] = nullptr;
        samples[i][j] = nullptr;
    }
    delete []samples_Frame[i];
    delete []samples[i];
    delete []samples_ave[i];
    delete []samples_sumsqr[i];
    delete []samples_ForeNum[i];
    delete []samples_BGInner[i];
    delete []samples_InnerState[i];
    delete []samples_BlinkLevel[i];
    delete []samples_MaxInnerGrad[i];



    samples_Frame[i] = nullptr;
    samples[i] = nullptr;
    samples_ave[i] = nullptr;
    samples_sumsqr[i] = nullptr;
    samples_ForeNum[i] = nullptr;
    samples_BGInner[i] = nullptr;
    samples_InnerState[i] = nullptr;
    samples_BlinkLevel[i] = nullptr;
    samples_MaxInnerGrad[i] = nullptr;

}
delete []samples_Frame;
delete []samples;
delete []samples_ave;
delete []samples_sumsqr;
delete []samples_ForeNum;
delete []samples_BGInner;
delete []samples_InnerState;
delete []samples_BlinkLevel;
delete []samples_MaxInnerGrad;

samples_Frame = nullptr;
samples = nullptr;
samples_ave = nullptr;
samples_sumsqr = nullptr;
samples_ForeNum = nullptr;
samples_BGInner = nullptr;
samples_InnerState = nullptr;
samples_BlinkLevel = nullptr;
samples_MaxInnerGrad = nullptr;

}

Useless loop

Hi! I have your implementation of ViBe+ reviewed and realized that in function

void ViBePlus::UpdatePixSampleSumSquare(int i, int j, int k, int val)
{
    double res = 0;
    UpdatePixSampleAve(i, j, k, val);
    for(int m = 0; m < num_samples; m++)
        res += pow(samples[i][j][m] - samples_ave[i][j], 2);
    res /= num_samples;
    samples_sumsqr[i][j] = res;
}

the loop is useless. Because it's adding to res a value of expression pow(samples[i][j][k] - samples_ave[i][j], 2) <num_samples> times. Then res is dividing by num_samples. So this loop and dividing are equals to res = pow(samples[i][j][k] - samples_ave[i][j], 2).

That is why I'm suggesting that there must be a samples[i][j][m] instead of samples[i][j][k]. Otherwise this loop is useless.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.