schappim / macOCR

Get any text on your screen into your clipboard.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not work on Chinese language

kevinnerd opened this issue · comments

Hi, it seems this tool can't work properly on image with Chinese language, does it only work with English ?
Will Chinese be supported later versions ?

commented

Modify line 52 of main.swift to have:

request.recognitionLanguages = ["zh", "en"]

Then it will work.

Hi Kevin,

Thanks for your email!

The underlying API can support both Traditional and Simplified Chinese characters.

Could you please let me know what the output of this script is:

#!/usr/bin/swift

import Foundation
let locale = NSLocale.autoupdatingCurrent

let code = locale.languageCode!
let language = locale.localizedString(forLanguageCode: code)!

print("\(code)")
print("\(language)")

We can then set the recognitionLanguages based on the output.

Modify line 52 of main.swift to have:

request.recognitionLanguages = ["zh", "en"]

Then it will work.

很不错,这个可以生效,注意:替换ocr文件后, 需要再次执行sudo cp ocr /usr/local/bin;,才会生效

import Foundation
let locale = NSLocale.autoupdatingCurrent

let code = locale.languageCode!
let language = locale.localizedString(forLanguageCode: code)!

print("\(code)")
print("\(language)")

zh
中文
locale: Locale = {}
code: String = "zh"
language: String = "中文"

On my system supported languages right now:

Screen Shot 2021-05-24 at 23 53 48

So maybe you will need to put full locale name e.g. zh-Hans or zh-Hant

BTW here the snippet to retrieve supported languages:

var possibleLanguages: Array<String> = []
let revision = VNRecognizeTextRequest.currentRevision

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

I'm trying to test with additional languages enabled.
I am based in Australia and for possibleLanguages, I'm only getting back en-US.

I have enabled additional languages in the Language & Region settings (and rebooted).
image of macOS 10.5 Language and Region preferences

Could this be a macOS 11 and above feature?

After testing on a Macbook Air w/ Big Sur, I can confirm this is a feature only available to macOS 11 and above.

Supported languages not related to Language & Region settings. This depends on the revision of the Vision framework...

@h0x91b , you of course are right!

I was testing on Catalina, and it works fine on Big Sur.

We might still want to use the Language & Region to set the recognitionLanguages sort order.

commented

I'd like to see a command line option for the languages too.

Please test with Intel Version: https://files.littlebird.com.au/ocr-XynT9NApdOnkqeCYrkLxJOHcjFpi.zip

Please note that the Chinese Support required Big Sur.

Modify line 52 of main.swift to have:

request.recognitionLanguages = ["zh", "en"]

Then it will work.

how to open this?

Please share list of supported languages and add CLI parameter to check version

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

meet same problem.

Bigsur 11.6 Chinese mess