frame differencing

128 views
Skip to first unread message

brigit

unread,
Dec 6, 2012, 1:12:58 PM12/6/12
to android...@googlegroups.com


Hi,

I am trying to implement a straightforward frame differencing between two successive frames,
within the ColorBlobDetection example (mostly just a place to test things). I capture 2 frames
with a delay in between and absdiff() them, but no matter what I do, the diff frame is always black (i'm able to 
display the normal undiffed  images just fine.

Here is my code; I usually code in C++ btw:


capture.retrieve(grey1, Highgui.CV_CAP_ANDROID_GREY_FRAME); // grey image

// artificial delay of 1 sec for testing; move camera

try {

      Thread.sleep(1000);

} catch (InterruptedException e1) {

// TODO Auto-generated catch block

       e1.printStackTrace();

}

capture.retrieve(grey2, Highgui.CV_CAP_ANDROID_GREY_FRAME); // grey image

// frame differencing - i've tried scaling the values too, but that doesn't seem to help

Core.absdiff(grey1,grey2, grey2);

// this part is a bit summarized

Bitmap mBmp = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(), Bitmap.Config.RGB_565);

Utils.matToBitmap(grey2, mBmp);


Can anyone please suggest what might be the problem? Using this approach in regular OpenCV usually works fine.


thanks,

brigit

Andrey Pavlenko

unread,
Dec 7, 2012, 8:27:51 AM12/7/12
to android...@googlegroups.com
when you take a diff of two opaque pixels with alpha==255, you're getting a transparent pixel with alpha==0 that looks black.
For displaying use
grey2 += Scalar(0, 0, 0, 255);
before conversion to Bitmap.

brigit

unread,
Dec 7, 2012, 12:05:16 PM12/7/12
to android...@googlegroups.com

thanks very much! this helped the screen to be visible at least,
but i don't actually see any differencing.

this is what i am doing:

Core.absdiff(grey1,grey2, grey2);

Core.add(grey2, new Scalar(32, 32, 32, 255), grey2);

i added 32 just to see something. I am grabbing my frames 1
second apart, but not seeing any differencing. they each display 
fine on their own. any suggestions? I am going to see if I can 
save off the images somehow to look at....Debug mode in Eclipse
allows you to see info about a Mat structure, but not the actually
data (even binary).

thanks!
brigit

--
 
 
 

Andrey Pavlenko

unread,
Dec 14, 2012, 2:35:22 AM12/14/12
to android...@googlegroups.com
Try to log both Mat-s as Strings and compare native addresses of their elements: the VideoCapture possibly returns a reference to its internal Mat that is overwritten on every frame (to avoid extra copying).
You need to use Mat::clone() to make a copy of particular frame.

brigit

unread,
Dec 14, 2012, 8:03:56 AM12/14/12
to android...@googlegroups.com

thank you! this makes a lot of sense. I will let you know how it turns out.

brigit/

On Fri, Dec 14, 2012 at 2:35 AM, Andrey Pavlenko <andrey....@itseez.com> wrote:
Try to log both Mat-s as Strings and compare native addresses of their elements: the VideoCapture possibly returns a reference to its internal Mat that is overwritten on every frame (to avoid extra copying).
You need to use Mat::clone() to make a copy of particular frame.

--
 
 
 

Reply all
Reply to author
Forward
0 new messages