Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def recognize(img, lang, *, hints=None):
if hints == None:
hints = []
if OcrHint.SINGLE_LINE in hints:
img = ImageOps.expand(img, 32, fill=img.getpixel((0, 0)))
lang = Language(lang)
assert (OcrEngine.is_language_supported(lang))
eng = OcrEngine.try_create_from_language(lang)
swbmp = _swbmp_from_pil_image(img)
return _dump_ocrresult(_blocking_wait(eng.recognize_async(swbmp)))
def recognize(img, lang, *, hints=None):
if hints == None:
hints = []
if OcrHint.SINGLE_LINE in hints:
img = ImageOps.expand(img, 32, fill=img.getpixel((0, 0)))
lang = Language(lang)
assert (OcrEngine.is_language_supported(lang))
eng = OcrEngine.try_create_from_language(lang)
swbmp = _swbmp_from_pil_image(img)
return _dump_ocrresult(_blocking_wait(eng.recognize_async(swbmp)))
def bind_model(model, image_frame):
device = winml.LearningModelDevice(winml.LearningModelDeviceKind.DEFAULT)
session = winml.LearningModelSession(model, device)
binding = winml.LearningModelBinding(session)
image_feature_value = winml.ImageFeatureValue.create_from_video_frame(image_frame)
binding.bind("data_0", image_feature_value)
shape = winml.TensorFloat.create([1, 1000, 1, 1])
binding.bind("softmaxout_1", shape)
return (session, binding)
def load_model(model_path):
return winml.LearningModel.load_from_file_path(os.fspath(model_path))
def evaluate_model(session, binding):
results = session.evaluate(binding, "RunId")
o = results.outputs["softmaxout_1"]
result_tensor = winml.TensorFloat._from(o)
return result_tensor.get_as_vector_view()
def bind_model(model, image_frame):
device = winml.LearningModelDevice(winml.LearningModelDeviceKind.DEFAULT)
session = winml.LearningModelSession(model, device)
binding = winml.LearningModelBinding(session)
image_feature_value = winml.ImageFeatureValue.create_from_video_frame(image_frame)
binding.bind("data_0", image_feature_value)
shape = winml.TensorFloat.create([1, 1000, 1, 1])
binding.bind("softmaxout_1", shape)
return (session, binding)
def bind_model(model, image_frame):
device = winml.LearningModelDevice(winml.LearningModelDeviceKind.DEFAULT)
session = winml.LearningModelSession(model, device)
binding = winml.LearningModelBinding(session)
image_feature_value = winml.ImageFeatureValue.create_from_video_frame(image_frame)
binding.bind("data_0", image_feature_value)
shape = winml.TensorFloat.create([1, 1000, 1, 1])
binding.bind("softmaxout_1", shape)
return (session, binding)
def bind_model(model, image_frame):
device = winml.LearningModelDevice(winml.LearningModelDeviceKind.DEFAULT)
session = winml.LearningModelSession(model, device)
binding = winml.LearningModelBinding(session)
image_feature_value = winml.ImageFeatureValue.create_from_video_frame(image_frame)
binding.bind("data_0", image_feature_value)
shape = winml.TensorFloat.create([1, 1000, 1, 1])
binding.bind("softmaxout_1", shape)
return (session, binding)
def _ibuffer(s):
"""create WinRT IBuffer instance from a bytes-like object"""
return CryptographicBuffer.decode_from_base64_string(base64.b64encode(s).decode('ascii'))
def bind_model(model, image_frame):
device = winml.LearningModelDevice(winml.LearningModelDeviceKind.DEFAULT)
session = winml.LearningModelSession(model, device)
binding = winml.LearningModelBinding(session)
image_feature_value = winml.ImageFeatureValue.create_from_video_frame(image_frame)
binding.bind("data_0", image_feature_value)
shape = winml.TensorFloat.create([1, 1000, 1, 1])
binding.bind("softmaxout_1", shape)
return (session, binding)