Export to GitHub

ehci - issue #7

OpenCV: Problem with finding a difference between a video frame and a fixed frame..


Posted on Jul 5, 2009 by Helpful Rhino

Hi!

I wanna do something like this: http://www.youtube.com/watch?v=aE0F4F5WIuI&feature=channel_page I wrote a code but it doesn't work :)

I don't know why but I think it should work! Take a look at this: http://rapidshare.de/files/47764349/bg.tar.bz2.html it is the full source based on "background.tar.gz-code" ( the author is: http://www.youtube.com/ user/dannyxyz22 )

First I take a cam shot where I'm gone from the cam view. Then I try to find a difference between two IplImages: canvas (current video frame) and bgWithoutFace (fixed frame without me in it). But it doesn't work. I have no ideas why it happens.. It's just not work :)

Does anyone have any suggestions?

I use Gentoo Linux. C++, SDL + OpenCV.

Attachments

Comment #1

Posted on Jul 5, 2009 by Helpful Rhino

I think I know what the problem.. My camera (Logitech Quick Communicate Deluxe) uses "auto-light". (when the scene too dark my webcam makes more light..). That's why every frames are different! But.. how can I disable this function in Linux? (My webcam uses the UVC driver)

Comment #2

Posted on Jul 5, 2009 by Helpful Rhino

Comment deleted

Comment #3

Posted on Jul 5, 2009 by Helpful Rhino

Is there any recommendations for webcamera settings? (contrast, brightness, saturaion, etc..?) I think my web cam has very bad image...

Comment #4

Posted on Jul 6, 2009 by Helpful Rhino

My webcam shows me a strange fuzzy-effect when I set "saturation"-option to the maximum: http://rapidshare.de/files/47770677/capture2.avi.html

Comment #5

Posted on Jul 6, 2009 by Helpful Rabbit

Hi Denis, thanks for posting here. Unfortunately I'm firewalled right now so I don't have access to rapidshare. So, your idea of subtracting is going to work, but not that greatly. You will get better results trying to average the background. But your conclusion is really correct. The auto-light function will make it not work under varying combinations of light. You should use an application like logitech's uvcdynctrl (http://www.quickcamteam.net/software/libwebcam) to disable the Backlight Compensation. It's something like this:

[baggio@baggio ~]$ uvcdynctrl -c Listing available controls for device video0: Backlight Compensation Sharpness Power Line Frequency Gamma Hue Saturation Contrast Brightness

You can get the value like: [baggio@baggio ~]$ uvcdynctrl -g 'Backlight Compensation' 1

And then unset it like: [baggio@baggio ~]$ uvcdynctrl -s 'Backlight Compensation' 0 And make sure it has worked: [baggio@baggio ~]$ uvcdynctrl -g 'Backlight Compensation' 0 Lots of computer vision effects rely on not changing the backlight, but you can try to make your method robust to it.

I hope it's going to be ok with this setting. Kind regards, Daniel

Comment #6

Posted on Jul 7, 2009 by Helpful Rhino

Here is the copy: http://www.youtube.com/watch?v=4tA6Vp5zgY8 (with HQ)

I can change those settings with the "gUVCView" program. I think my webcam has very bad quality for computer vision and for problem like mine :(

Comment #7

Posted on Jul 7, 2009 by Helpful Rabbit

Hum... well... How are you subtracting the images (sorry for being blocked with rapidshare here)... Can you post this part?

There isn't much requirement for a perfect image to do subtraction. A low quality should work fine.

Comment #8

Posted on Jul 7, 2009 by Helpful Rhino

Comment deleted

Comment #9

Posted on Jul 7, 2009 by Helpful Rhino

I just do:

for( int i = 0; i < videoFrame->height; i++ ){ for( int j = 0; j < videoFrame->width; j++ ){

    CvScalar c1, c2;

    c1 = cvGetAt( bgWithoutFace, i, j );
    c2 = cvGetAt( canvas, i, j );

    Uint32 myPixel;

    if ( ( c1.val[ 0 ] == c2.val[ 0 ] ) && 
        ( c1.val[ 1 ] == c2.val[ 1 ] ) && 
        ( c1.val[ 2 ] == c2.val[ 2 ] ) ) {

        myPixel =   ( ( int ) cvGetAt( backgroundImage, i, j ).val[ 2 ] << 16 ) |
                    ( ( int ) cvGetAt( backgroundImage, i, j ).val 

[ 1 ] << 8 ) | ( ( int ) cvGetAt( backgroundImage, i, j ).val [ 0 ] );

    } else {

        myPixel =   ( ( int ) cvGetAt( canvas, i, j ).val[ 2 ] << 16 ) |
                    ( ( int ) cvGetAt( canvas, i, j ).val[ 1 ] << 8 )  |
                    ( ( int ) cvGetAt( canvas, i, j ).val[ 0 ] );

    }

    putpixel( image, j, i, myPixel );

}       

}

Comment #10

Posted on Jul 8, 2009 by Helpful Rabbit

Hum... try changing the order of the values RGB -> BGR, and make sure the size of myPixel is correct (is it RGBA?). Good luck! []'s

Comment #11

Posted on Jul 8, 2009 by Helpful Rhino

try changing the order of the values RGB -> BGR but why it's so important? I just check a difference between two pixels... I think the order it's not important here... or not? :)

(is it RGBA?). Hm I think it's RGB.. ("Bytes per pixel: 3") Why did you ask me about RGBA?

Comment #12

Posted on Jul 8, 2009 by Helpful Rhino

By the way there's my code: http://pastebin.ca/1488001 I meant.. there's your code :))) cause my attempts based on your "background.tar.gz"-file.

Comment #13

Posted on Jul 8, 2009 by Helpful Rhino

I add following:

CvScalar c1, c2;

c1 = cvGetAt( bgWithoutFace, i, j ); c2 = cvGetAt( canvas, i, j );

int dSum = abs( c1.val[ 0 ] - c2.val[ 0 ] ) + abs( c1.val[ 1 ] - c2.val[ 1 ] ) + abs( c1.val[ 2 ] - c2.val[ 2 ] );

if ( dSum < 30 ) {

...

Now it works better.. But sometimes it shows holes in your body :)

Comment #14

Posted on Jul 8, 2009 by Helpful Rabbit

Great, you've done some progress... well, the software from OSX is not that perfect as well... I think we can get by with it... Good work!

Comment #15

Posted on Jul 8, 2009 by Helpful Rabbit

I think the issue can be closed now, all right?

Comment #16

Posted on Jul 9, 2009 by Helpful Rhino

Great, you've done some progress... A little progress :D

Yes, I think the issue can be closed now!

Comment #17

Posted on Jul 9, 2009 by Helpful Rabbit

Great, thanks for sharing :)

Comment #18

Posted on Jul 9, 2009 by Helpful Rhino

You're welcome :) I try to find more intresting things in OpenCV!

Comment #19

Posted on Jun 8, 2011 by Happy Giraffe

Hi ,

I am new one with open cv work for image processing . I am using MFC c++ and open cv for detecting the object boundry..for that i first need to find the difference between all frames of video . But i do't have any idea for this .. I googled it but i am getting more confuse .. Please guide me with some source code .. that how can id find the difference between all frames .. Please help me its urgent,. thanks

Comment #20

Posted on Jun 9, 2011 by Helpful Rabbit

Well, I'd point you to check the Motempl example that comes with openCV. You'll get a good idea on how to get the difference between frames reading that code.

Best regards, Daniel

Status: Done

Labels:
Type-Task Priority-Medium