How to compare two images in JavaCV?

1,637 views
Skip to first unread message

satio

unread,
Jul 7, 2010, 10:40:52 PM7/7/10
to javacv
Hi, is there any method to compare two images in JavaCV?
and the result show how many percent(%) the images are similiar..
can you give me some examples about that?
thank you..

Samuel Audet

unread,
Jul 7, 2010, 10:51:44 PM7/7/10
to jav...@googlegroups.com

You could modify the ObjectFinder to fit your needs.. Here is some code
that shows how to use it:
http://code.google.com/p/javacv/source/browse/trunk/procamtracker/src/name/audet/samuel/procamtracker/TrackingWorker.java#312

Samuel

satio

unread,
Jul 7, 2010, 11:39:14 PM7/7/10
to javacv
thanks for the fast reply, but i still find some difficulty about the
code.
My problem is the two images are manually loaded, not from the camera.
My example code is like this :

IplImage image = highgui.cvLoadImage("gambar.png", 1);
if (image == null) {
return;
}

IplImage image2 = highgui.cvLoadImage("gambar.png", 2);
if (image2 == null) {
return;
}

CanvasFrame frame = new CanvasFrame("Frame1");
frame.showImage(image);
CanvasFrame frame2 = new CanvasFrame("Frame2");
frame2.showImage(image2);

And i want to show how many percent the difference between the two
images..
Can you give me some cluehow to finish that code?
Thanks.

Satio.

On Jul 8, 9:51 am, Samuel Audet <samuel.au...@gmail.com> wrote:
> On 2010-07-08 11:40, satio wrote:
>
> > Hi, is there any method to compare two images in JavaCV?
> > and the result show how many percent(%) the images are similiar..
> > can you give me some examples about that?
> > thank you..
>
> You could modify the ObjectFinder to fit your needs.. Here is some code
> that shows how to use it:http://code.google.com/p/javacv/source/browse/trunk/procamtracker/src...
>
> Samuel

Jeremy NICOLA

unread,
Jul 8, 2010, 12:42:12 AM7/8/10
to jav...@googlegroups.com
Hi Satio,

seems like you're not looking for a "professional way" to do this, so here is an idea ( if you really only want to compare two images, without trying to characterize anything in them ) :

Cut your images into some sub-rectangles, of which you chose the size depending on the "precision" you want ( the biggest the rectangles, the lowest the precision ), calculate the average value of the pixels of each channel in this area, and compare the values you've got between the two images.

If you want to do it more efficiently ( regarding to the results, not to the execution-time ) you should look at "cross-correlation product" although I've no idea how ( and if ) it works in image processing.

Good luck,

Jeremy

2010/7/7 satio <fendy...@gmail.com>

Samuel Audet

unread,
Jul 9, 2010, 3:39:45 PM7/9/10
to jav...@googlegroups.com
I do not know what your application is, but you may define a probability
on the similarity of the two images based on the number of geometrically
valid feature points they have in common. The most popular feature point
algorithm are SIFT and SURF, an optimized version of SIFT. OpenCV comes
with SURF. You can read all about SIFT and SURF feature points on these
two sites:
http://www.cs.ubc.ca/~lowe/keypoints/
http://www.vision.ee.ethz.ch/~surf/
Good luck

Samuel

Reply all
Reply to author
Forward
0 new messages