Which languages are available for text recognition in Vision framework?
Asked Answered
N

3

8

I'm trying to add the option to my app to allow for different languages when using Apple's Vision framework for recognising text.

There seems to be a function for programmatically returning the supported languages but I'm not sure if I'm calling it correctly because I'm only getting "en-US" back which I'm fairly sure isn't the only supported language?

Here's what I currently have:

// current revision number of Vision
let revision = VNRecognizeTextRequest.currentRevision
var possibleLanguages: Array<String> = []

do {
    possibleLanguages = try VNRecognizeTextRequest.supportedRecognitionLanguages(for: .accurate, 
                                                                            revision: revision)
} catch {
    print("Error getting the supported languages.")
}

print("Possible languages for revision \(revision):\n(possibleLanguages.joined(separator: "\n"))")

Any help would be much appreciated, thank you.

Necessary answered 3/10, 2019 at 13:3 Comment(4)
I think the language has to be added in the device settings. What device of are running this on? Does that device only have English set in its setting?Censure
Thanks, I like the thought but I’m on a device that is en-GB only. Just tried adding Russian language to my device and it still shows en-US only.Necessary
@Necessary Did you find any solution for this. I have to add support for other languages as well.Carbuncle
@Carbuncle I still haven't I'm afraid. Let me know if you come across a solution, thanks!Necessary
A
6

iOS 15

In iOS 15 you can call the following instance method that returns the identifiers of the languages that the request (VNRecognizeTextRequest) supports:

func supportedRecognitionLanguages() throws -> [String]

You can use it this way:

print(try! request.supportedRecognitionLanguages())

A. Result (if you use .accurate recognitionLevel):

// ["en-US", "fr-FR", "it-IT", "de-DE", "es-ES", "pt-BR", "zh-Hans", "zh-Hant"]

B. Result (if you use .fast recognitionLevel):

// ["en-US", "fr-FR", "it-IT", "de-DE", "es-ES", "pt-BR"]


recognitionLanguages property

You can easily tell Vision framework which languages are needed for text recognition using recognitionLanguages instance property:

var recognitionLanguages: [String] { get set }

According to Apple documentation: recognitionLanguages defines the order in which languages are used during language processing and text recognition.Specify the languages as ISO language codes.

A real code may look like this:

import Vision

let recognizeTextRequest = VNRecognizeTextRequest()
recognizeTextRequest.minimumTextHeight = 0.05
recognizeTextRequest.recognitionLevel = .accurate

recognizeTextRequest.recognitionLanguages = ["en-US", "fr-FR", "zh-Hans"]

P.S.

In the beginning of 2020, Vision supported only English.

Astrolabe answered 12/3, 2020 at 12:56 Comment(2)
Thanks for you answer, this is what I ended up having but I still couldn’t get any other languages to recognise. I went back and watched the WWDC video about it and there’s one quick moment where they say they only support En-US for the first version. I’m sure they’ll add more with iOS14.Necessary
@mralexhay, you're right, it supports only English at the moment.Astrolabe
D
9

As of iOS 14, VNRecognizeTextRequestRevision2 supports English, French, Italian, German, Spanish, Portuguese, and Chinese (both Simplified and Traditional) in the .accurate recognition level.

["en-US", "fr-FR", "it-IT", "de-DE", "es-ES", "pt-BR", "zh-Hans", "zh-Hant"]

The .fast recognition level supports English, French, Italian, German, Spanish, and Portuguese.

["en-US", "fr-FR", "it-IT", "de-DE", "es-ES", "pt-BR"]

You can check in Playground with this snippet:

try VNRecognizeTextRequest.supportedRecognitionLanguages(for: .fast, revision: 2)
Diaphragm answered 20/9, 2020 at 7:7 Comment(0)
A
6

iOS 15

In iOS 15 you can call the following instance method that returns the identifiers of the languages that the request (VNRecognizeTextRequest) supports:

func supportedRecognitionLanguages() throws -> [String]

You can use it this way:

print(try! request.supportedRecognitionLanguages())

A. Result (if you use .accurate recognitionLevel):

// ["en-US", "fr-FR", "it-IT", "de-DE", "es-ES", "pt-BR", "zh-Hans", "zh-Hant"]

B. Result (if you use .fast recognitionLevel):

// ["en-US", "fr-FR", "it-IT", "de-DE", "es-ES", "pt-BR"]


recognitionLanguages property

You can easily tell Vision framework which languages are needed for text recognition using recognitionLanguages instance property:

var recognitionLanguages: [String] { get set }

According to Apple documentation: recognitionLanguages defines the order in which languages are used during language processing and text recognition.Specify the languages as ISO language codes.

A real code may look like this:

import Vision

let recognizeTextRequest = VNRecognizeTextRequest()
recognizeTextRequest.minimumTextHeight = 0.05
recognizeTextRequest.recognitionLevel = .accurate

recognizeTextRequest.recognitionLanguages = ["en-US", "fr-FR", "zh-Hans"]

P.S.

In the beginning of 2020, Vision supported only English.

Astrolabe answered 12/3, 2020 at 12:56 Comment(2)
Thanks for you answer, this is what I ended up having but I still couldn’t get any other languages to recognise. I went back and watched the WWDC video about it and there’s one quick moment where they say they only support En-US for the first version. I’m sure they’ll add more with iOS14.Necessary
@mralexhay, you're right, it supports only English at the moment.Astrolabe
S
2

For iOS 16 release, this method for checking languages support

print(try! VNRecognizeTextRequest().supportedRecognitionLanguages())

returns the following list of languages:

["en-US", "fr-FR", "it-IT", "de-DE", "es-ES", "pt-BR", "zh-Hans", "zh-Hant", "yue-Hans", "yue-Hant", "ko-KR", "ja-JP", "ru-RU", "uk-UA"]
Szymanowski answered 15/9, 2022 at 4:58 Comment(3)
Is this for .accurate only?Lambart
VNRecognizeTextRequest() has recognitionLevel == .accurate by default, so yes, it is for .accurate case.Szymanowski
in iOS 17 added support of "th-TH", "vi-VT"Pugilism

© 2022 - 2024 — McMap. All rights reserved.