Apple's Photo app has facial recognition capabilities. I would like to know if an API exists to access the associated data for photos which have been classified by the app.
How to access People album used in Apple's Photos app
1.2k Views Asked by Edan At
3
There are 3 best solutions below
2
On
Apple released an SDK for accessing Apple Photos called Photo Kit. In the documentation, you will find API access to the photos application and photos cloud. However, if you are looking for an HTTP API I do not believe one has been announced publicly.
If you only need access to is data on Photos MacOS app I would recommend digging through the SQLite photos.db located in the photos library database directory.
/Users/[yourUserName]/Pictures/Photos Library.photoslibrary/database/photos.db
I am working on a project this weekend that requires similar face data and will document my progress. Here is a sample SQLite query you can use to get all faces, photos, and corresponding person:
SELECT *, RKFace.modelId AS fId
FROM RKFace
JOIN RKMaster ON RKMaster.modelId = RKFace.imageModelId
LEFT JOIN RKFaceGroup ON RKFaceGroup.modelId = RKFace.faceGroupId
LEFT JOIN RKFaceCrop ON RKFaceCrop.faceId = RKFace.imageModelId
LEFT JOIN RKFacePrint ON RKFacePrint.faceId = RKFace.imageModelId
LEFT JOIN RKPerson ON RKPerson.modelId = RKFace.personId;
I hope this helps. :-)
The file
photos.dbmentioned by Adrian unfortunately did not contain the data anymore in 2021. However, I found a big file called/Users/[yourUserName]/Pictures/Photos Library.photoslibrary/database/Photos.sqlitethat looked promising. Here's an SQL query that will return all photos of myself as an example:The returned columns are
FULL_NAME,FILENAMEandDATECREATED. The resulting date is specified as a Unix timestamp in seconds, though it may also contain a fraction. For example,1618068987.64944refers to3:36:27 pm UTC | Saturday, April 10, 2021.For reference,
978307200is the difference between the Apple epoch and the Unix epoch in seconds. I obtained it in Python through this expression:(datetime(2001, 1, 1, 0, 0) - datetime(1970, 1, 1, 0, 0)).total_seconds().