From 72af96b48ee7552d5d35e6f5d619c5b7a55050ab Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sun, 15 May 2022 14:50:07 -0700 Subject: [PATCH] Added example --- examples/detect_text_in_photos.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 examples/detect_text_in_photos.py diff --git a/examples/detect_text_in_photos.py b/examples/detect_text_in_photos.py new file mode 100644 index 00000000..cd3f3f4a --- /dev/null +++ b/examples/detect_text_in_photos.py @@ -0,0 +1,22 @@ +"""Use osxphotos and photoscript to find text in photos and update the photo description with detected text""" + +import photoscript + +import osxphotos + +if __name__ == "__main__": + # get photos selected in Photos + selection = photoscript.PhotosLibrary().selection + photosdb = osxphotos.PhotosDB() + photos = photosdb.photos(uuid=[s.uuid for s in selection]) + for photo in photos: + detected_text = photo.detected_text() + if not detected_text: + continue + # detected text is tuple of (text, confidence) + for text, confidence in detected_text: + description = photo.description or "" + # set confidence level to whatever you like + if confidence > 0.8 and text not in description: + print(f"Adding {text} to {photo.original_filename} ({photo.uuid})") + photoscript.Photo(photo.uuid).description += f" {text}"