jhzh / ehci

Automatically exported from code.google.com/p/ehci
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by denis1...@gmail.com on 5 Jul 2009 at 7:18

Attachments:

GoogleCodeExporter commented 9 years ago
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)

Original comment by denis1...@gmail.com on 5 Jul 2009 at 9:04

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Is there any recommendations for webcamera settings? (contrast, brightness, 
saturaion, etc..?)
I think my web cam has very bad image...

Original comment by denis1...@gmail.com on 5 Jul 2009 at 11:26

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

Original comment by denis1...@gmail.com on 6 Jul 2009 at 1:06

GoogleCodeExporter commented 9 years ago
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

Original comment by danielba...@gmail.com on 6 Jul 2009 at 11:07

GoogleCodeExporter commented 9 years ago
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 :(

Original comment by denis1...@gmail.com on 7 Jul 2009 at 12:00

GoogleCodeExporter commented 9 years ago
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.

Original comment by danielba...@gmail.com on 7 Jul 2009 at 12:17

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
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 );

    }       
}
---------------------------------------

Original comment by denis1...@gmail.com on 7 Jul 2009 at 9:39

GoogleCodeExporter commented 9 years ago
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

Original comment by danielba...@gmail.com on 8 Jul 2009 at 2:22

GoogleCodeExporter commented 9 years ago
>> 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?

Original comment by denis1...@gmail.com on 8 Jul 2009 at 10:44

GoogleCodeExporter commented 9 years ago
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.

Original comment by denis1...@gmail.com on 8 Jul 2009 at 10:51

GoogleCodeExporter commented 9 years ago
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 :)

Original comment by denis1...@gmail.com on 8 Jul 2009 at 2:50

GoogleCodeExporter commented 9 years ago
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!

Original comment by danielba...@gmail.com on 8 Jul 2009 at 11:33

GoogleCodeExporter commented 9 years ago
I think the issue can be closed now, all right?

Original comment by danielba...@gmail.com on 8 Jul 2009 at 11:39

GoogleCodeExporter commented 9 years ago
>> Great, you've done some progress...
A little progress :D

Yes, I think the issue can be closed now!

Original comment by denis1...@gmail.com on 9 Jul 2009 at 12:04

GoogleCodeExporter commented 9 years ago
Great, thanks for sharing :)

Original comment by danielba...@gmail.com on 9 Jul 2009 at 8:27

GoogleCodeExporter commented 9 years ago
You're welcome :) I try to find more intresting things in OpenCV!

Original comment by denis1...@gmail.com on 9 Jul 2009 at 9:07

GoogleCodeExporter commented 9 years ago
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 

Original comment by rabiafy...@gmail.com on 8 Jun 2011 at 9:01

GoogleCodeExporter commented 9 years ago
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

Original comment by danielba...@gmail.com on 9 Jun 2011 at 1:58