From 7376223eb87a4919fd54cc685a3f263e83626879 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Thu, 29 Jul 2021 07:39:01 -0700 Subject: [PATCH] Updated text_detection to detect macOS version --- osxphotos/text_detection.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/osxphotos/text_detection.py b/osxphotos/text_detection.py index e460f12e..7f757652 100644 --- a/osxphotos/text_detection.py +++ b/osxphotos/text_detection.py @@ -1,19 +1,33 @@ -""" Use Apple's Vision Framework via PyObjC to perform text detection on images """ +""" Use Apple's Vision Framework via PyObjC to perform text detection on images (macOS 10.15+ only) """ + +import logging +from typing import List import objc import Quartz -import Vision from Cocoa import NSURL from Foundation import NSDictionary -from typing import List - # needed to capture system-level stderr from wurlitzer import pipes +from .utils import _get_os_version + +ver, major, minor = _get_os_version() +if ver == "10" and int(major) < 15: + vision = False +else: + import Vision + + vision = True + def detect_text(img_path: str) -> List: """process image at img_path with VNRecognizeTextRequest and return list of results""" + if not vision: + logging.warning(f"detect_text not implemented for this version of macOS") + return [] + with objc.autorelease_pool(): input_url = NSURL.fileURLWithPath_(img_path)