OpenCV Background substraction using Absdiff
<p>I've been working about a program to detect hands by background substracting.
I have tried to save the first frame of a camera as Background and substract with current frame, but it appeared that they have different brightness somehow.
I've tried it several times and I dont have and light changing, what can be the problem?
<a href="http://i.stack.imgur.com/rJgNl.jpg" rel="nofollow">image1</a>
<a href="http://i.stack.imgur.com/KkA0O.jpg" rel="nofollow">image2</a></p>

<pre><code>#include &lt;opencv2/highgui/highgui.hpp&gt;
#include &lt;opencv2/imgproc/imgproc.hpp&gt;
#include &lt;iostream&gt;
#include "Camera.h"
#include &lt;opencv2/core/core.hpp&gt;
#include &lt;opencv2/highgui/highgui.hpp&gt;
#include &lt;opencv2/video/background_segm.hpp&gt;
using namespace cv;
using namespace std;
int main() {
    const int LAPTOP_CAM = 0;
    const int LIFECAM = 1;
    const int MAX_FPS = 25;
    Camera cam(LIFECAM);
    Mat backGround;

    cam.TakeShot();
    cam.MirrorImage();

    cam.getFrame().copyTo(backGround); //Deep Copy
    imshow("Background", backGround);
    Mat diff;
    while (true) {
        cam.TakeShot();
        cam.MirrorImage();
        absdiff(cam.getFrame(),backGround , diff);

        imshow("Result", cam.getFrame());
        imshow("Diff", diff);

        cam.Set_FPS(MAX_FPS);

        if (waitKey(1) == 27)
            break;

    }

}
</code></pre>

<p>here is "Camera.cpp":</p>

<pre><code>#include "Camera.h"
Camera::Camera()
{
}


Camera::~Camera()
{

}
Camera::Camera(int camNum)
{
    VideoCapture cap(camNum);
    _capture = cap;
}
void Camera::TakeShot()
{
    _capture &gt;&gt; _frame;
}
void Camera::Set_FPS(int fps)
{
    if (fps &gt; 25)
        fps = 25;
    else if (fps &lt; 1)
        fps = 1;
    _capture.set(CV_CAP_PROP_FPS, fps);
}
Mat Camera::getFrame()
{
    return _frame;
}
void Camera::MirrorImage()
{
    flip(_frame, _frame, 1);
}
</code></pre>