-1

How to compare one image token with camera with all the other images stored in the sd card and display the result?

public class SearchForFaces extends Activity {

    Bitmap bitmapOriginale;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Bundle b1 = getIntent().getExtras();
        String cin= b1.getString("cin");        

        //getting the image
        File sdCard = Environment.getExternalStorageDirectory();
        File directory = new File (sdCard.getAbsolutePath() + "/Student");
        File file = new File(directory, cin+"jpg");
        try {
            FileInputStream streamIn = new FileInputStream(file);
            bitmapOriginale = BitmapFactory.decodeStream(streamIn);
            streamIn.close();
        } catch (IOException e) {
            Log.d("SearchForFaces Exception", e.getMessage());
        }
        if(bitmapOriginale.sameAs(//images from sdcard)) 
        {
            //display founded image
        }
    }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
hamzarh
  • 330
  • 2
  • 6
  • 20
  • 1
    What are the criteria for comparison? If you want to compare two or more images and display a result you need to find or write an algorithm for it. – Marcin S. Sep 14 '12 at 00:45
  • i compare with sameAs(), i am just asking how i can compare with othr images because i have one image and i have to bring all others from sdcard so i can use image1.sameAS(images from sdcard). – hamzarh Sep 14 '12 at 00:50
  • So you have already written an algorithm and you have your method to compare two images. What is your question then? You don't know how to read rest of the images from sd card? – Marcin S. Sep 14 '12 at 00:54
  • Yes this is it so i can put them as arg in my comparaison method. – hamzarh Sep 14 '12 at 00:56
  • You should attach your code of the sameAs() method. but you might also want to check this http://stackoverflow.com/questions/6725718/android-display-image-from-sd-card of how to read an image from sdcard – Marcin S. Sep 14 '12 at 01:00

2 Answers2

0

Check also this blog http://mihaifonoage.blogspot.com/2009/09/displaying-images-from-sd-card-in.html It shows how to read an images from sd card. Once you read them you can use your sameAs() written method to compare them.

Marcin S.
  • 11,161
  • 6
  • 50
  • 63
0

i think, its not necessary read all images..if you want compare images from camera, you can "easy" take the images in DCMI folder. But ok, user will move some files in another folder. So in that case i will advice just open first folder, read files in there and check the format, after that open another folder, read files in there and again check the formats and save the paths to the jpg files.
So in this case just easy some for, foreach, while cykl or you can do it with recursion. You will have some ArrayList (linkedList, whatever) and in this list you can put the paths. Then just call your sameAs method.
On this you can use Environment.getExternalStorageDirectory().listFiles();

But..i am not sure if your "algorithm" will work..image recognition is really hard part of computer science..and if you dont know how to get the files on SDcard..the algorithm wouldnt probably work..
But if you want to check the similarity with byte by byte comparsion, then its ok..

tomdelahaba
  • 948
  • 3
  • 13
  • 26
  • byte to byte comparaison take too much time using bitmap.getPixel so i took the easy way using sameAs. – hamzarh Sep 14 '12 at 01:49
  • if you do byte by byte or getpixel is fast equal..but do you know, that the function is equal FALSE!! all the time :]..your probability to get 2 exactly SAME pictures is equal to 0..the quality of photos is really low and sun, or whatever will change you 1 pixel (in 5Mpx) it is 1/5000 of image size..so if this 1 pixel will be other, your function will return false..i am sure that all the time......... – tomdelahaba Sep 14 '12 at 01:56
  • if you want to write some "image" recognition, i will advice you better learn some algorithms, read something about that and then try to implement it. I really admire your enthusiasm in this. But visual recognition is really not so easy like comparing pixels..but i need to say, that i dont know what exactly does your sameAs method.. But i dont think, that you have in there some complex hard algorithm..its just advice, because this will be pretty "losed" your time and big fiasco for you.. – tomdelahaba Sep 14 '12 at 02:00