I want to detect programmatically whether a picture was taken with:

  • a front-facing camera,
  • a rear-facing camera,
  • or whether we can not tell.

Is there a library for that?


  • Works offline.
  • Open source.
  • It is for an Android app, so bonus for Java, but I can also do the porting so don't hesitate to post solutions in other languages.
  • Works with JPG's EXIF, bonus for other formats. Alternatively it could take EXIF properties values as input.
  • Reasonably fast, the detection should take less than a second once the image's data is loaded.
  • Aiming for around 97% reliability (excluding "we can not tell" cases).
  • Below 500 kilobytes.

The app is running on the phone that took the picture, solutions that take advantage of this fact are acceptable too.

Context: People usually take very different pictures depending on front/rear, so that would give my app very important hints.

Since EXIF does not seem to have a property for front/back, a solution could embed a database of phone models and guess from the model name and lens resolution as tipped at https://photo.stackexchange.com/questions/79179/rear-or-front-facing-camera-through-exif-data , OpenData question about such a database: https://opendata.stackexchange.com/questions/13581/focal-length-of-both-front-and-back-cameras-of-popular-smartphones

  • "People usually take very different pictures depending on front/rear" - can you explain? Frankly, I do not believe that what you ask can be done (except, perhaps, that large pictures of a single face are probably the front camera (or pics containing an arm/selfie-stick obviously holding the 'phone); or that if all pictures are from the same 'phone then there ought to be only two resolutions, with the larger being the rear camera) – Mawg says reinstate Monica Sep 13 '18 at 8:33
  • It can definitely be done. Just have your code take the model name, match it against an embedded database of phones focal lengths for both rear and front, and you are done. There might be smarter algorithms. More context for the curious: github.com/commons-app/apps-android-commons/issues/1898 – Nicolas Raoul Sep 13 '18 at 8:57
  • 1
    Yes, in parallel I am looking for a maintained database, and will ask at OpenData once I am confident about my requirements :-) Pictures with no EXIF are already considered as a separate case by the algorithm, so they are outside of scope. – Nicolas Raoul Sep 14 '18 at 2:13
  • 1
    I am still open to any other solution, though. In particular, I started thinking that if the Android API gives me the en.wikipedia.org/wiki/Field_of_view of each camera of the device, I might be able to figure out which one is the front and which one is the rear, because the front one usually has a larger field of view, I believe. Once again, if someone has figured it out already I would prefer to use their solution :-) – Nicolas Raoul Sep 14 '18 at 7:42
  • 4
    Some cameras do save it "exiftool IMG_20180913_200444.jpg | grep -i "Lens Facing" RESULT: Lens Facing : Back shot with (Camera Model Name : ONEPLUS A6003) – knb Sep 14 '18 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.