Home > Back-end >  is it possible to detect selfie image in android?
is it possible to detect selfie image in android?

Time:05-25

I have list of images from MediaStore.images.media. is it possible to detect selfie images? I have read about mlkit Selfie Segmentation, but I guess it is about changing the photo?

CodePudding user response:

You can try getting EXIF data from images and compare some parameters. Add the following dependency to your build.gradle if you wish to utilize ExifInterface:

implementation "androidx.exifinterface:exifinterface:1.3.3"

After that you can get EXIF data from photo following next code:

Uri gfgUri; // the file uri
InputStream gfgIn;
try {
    gfgIn = getContentResolver().openInputStream(gfgUri);
    ExifInterface exifInterface = new ExifInterface(gfgIn);
    // Extract the EXIF tag here
} catch (IOException e) {
    // Handle any errors
} finally {
    if (gfgIn != null) {
        try {
            gfgIn.close();
        } catch (IOException ignored) {}
    }
}

You can use, for example, photo resolution for comparing rare and front photos. The resolution often differs: the camera facing the user has a lower resolution than the camera on the back.

A few examples I pulled from gsmarena.com:

  • Google Pixel 6 Pro: Main: 50 MP; Selfie: 11.1 MP;
  • Apple iPhone SE (2022): Main: 12 MP; Selfie: 7 MP;
  • Samsung Galaxy S22 5G: Main: 50 MP; Selfie: 10 MP;
  • Related