Question:
How to compare 2 playing card images in java?
x2862
2010-08-20 10:54:44 UTC
I have 52 images of playing cards which I have uploaded here
http://members.dslextreme.com/users/x2862/images/

I also have 52 card images that are random taken with

BufferedImage r1c1 = screencapture.getSubimage(4,1,62,16);

the cards are from a freecell game and the r1c1 is row 1 column 1

what I cant figure out is how to compare the buffered image with the card images to see what card it is. I will be using that info for a freecell solver.
Three answers:
Jared
2010-08-20 11:49:22 UTC
There's no "easy" way to do what you are proposing.



First there's the question of equality. If you I show you two pictures of the same thing, you will right away say, yes they are the same?



Why, because all of the pixels look the same, right? The problem is that you don't care about minor details that may be different, but the computer DOES.





Naively:

You could just do a pixel-by-pixel comparison, which is what I suspect you want to do.



public static boolean comparePics(BufferedImage img1, BufferedImage img2){

int w = img1.getWidth();

int h = img1.getHeight();

if(w == img2.getWidth() && h == img2.getHeight()){

for(int i = 0; i < w; ++i){

for(int j = 0; j < h; ++j){

int c1 = img1.getRGB(i, j);

int c2 = img2.getRGB(i, j);

if(c1 != c2){

return false;

}

}

}

}else{

return false;

}

return true

}



That may not be completely syntactically correct, but you should be just missing a parenthesis or something.





WARNING:

If you have two pictures that are not the same size, then don't think that you can just scale them and then this will work, because it won't. This algorithm is VERY VERY picky. The likelihood of taking two identical pictures, scaling them to different sizes, then scaling them back and then that giving you back the EXACT same two pictures (pixel-by-pixel) is unlikely.



For instance when you scale a picture down, pixels have to be removed, so you are removing information, that information is no longer accessible from your scaled picture. Also if you scale images to be bigger, then pixels must be added, now you've added "bad" information to your picture.



Seriously, try this, take a picture. Now scale it down to a smaller size, now save as a new picture. Now take the new picture that you just scaled and blow it back up to the size of the original picture, do they look the same? I doubt it.
Warren
2010-08-20 11:10:19 UTC
If you are simply taking a random picture and dumping it somewhere, you have no chance of knowing what card is what.



What you need to figure out is a way to somehow get the suit and number (eg. H4, CK) into your program, then you can apply your algorithm.



I personally can't think of a way of telling the program to decipher an image and determine what it means. Consider creating an interface where a user can input the position of cards.



Or, you can create the position yourself, let the user try and solve, and then let your solver apply your algorithm.
?
2016-12-26 22:49:52 UTC
in case you could look ahead to a pair of months then look ahead to Micromax Canvas professional HD A120 that's coming with with a 2GHz Quad middle proccessor, 2GB RAM and 1080p show. 13MP digital camera. it would be priced around 17000rs. a sturdy telephone at this cost. And approximately high quality. micromax have better their build high quality very lots. you could discover evaluate of the main up-tp-date micromax canvas HD a116


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...