! OCR text from image (:ocr_text)
Declaration
text, details = img:ocr_text([ engine_options, binarization ])
Parameters
-
engine_options
Optional, table. Choose language and OCR engineStructure
{
-- engine = "apple" uses Vision.framework (iOS 13+)
-- Use image.vision_supported_recognition_languages() to list supported models
-- engine = "paddle" uses Paddle-Lite. Use lang like "ppocr_ch" for model path /var/mobile/Media/1ferver/models/ppocr_ch
-- Paddle-Lite supports Slim *.nb models
engine = "apple" | "paddle" | "tesseract",
lang = "zh-Hans",
}Vision.framework supported OCR models by iOS version
{ -- iOS 13
[1] = "en-US",
}
{ -- iOS 14~15
[1] = "en-US",
[2] = "fr-FR",
[3] = "it-IT",
[4] = "de-DE",
[5] = "es-ES",
[6] = "pt-BR",
[7] = "zh-Hans",
[8] = "zh-Hant",
}
{ -- iOS 16
[ 1] = "en-US",
[ 2] = "fr-FR",
[ 3] = "it-IT",
[ 4] = "de-DE",
[ 5] = "es-ES",
[ 6] = "pt-BR",
[ 7] = "zh-Hans",
[ 8] = "zh-Hant",
[ 9] = "yue-Hans",
[10] = "yue-Hant",
[11] = "ko-KR",
[12] = "ja-JP",
[13] = "ru-RU",
[14] = "uk-UA",
} -
binarization
Number: threshold. See Auto binarization
Table: custom binarization with tolerances. See Manual binarization
String: custom binarization with tolerances. See Manual binarization
Returns
-
text
String. Recognized text -
details
TableDetails structure
{
{
["y"] = number_value,
["x"] = number_value,
["w"] = number_value,
["h"] = number_value,
["confidence"] = number_value(0.0000 ~ 1.0000),
["text"] = string_value,
},
...
}
Description
Recognize text in an image. Except no region params, other usage is the same as screen.ocr_text
Available in app version >= 1.3.8
Examples
-- >=1.3.8
local img = image.load_file(XXT_SCRIPTS_PATH..'/1.png')
txt, info = img:ocr_text("en-US")
sys.toast("Result: "..txt:atrim())
txt, info = img:ocr_text("zh-Hans")
sys.toast("Result: "..txt:atrim())
txt, info = img:ocr_text({ engine = "apple", lang = "zh-Hans" }, "9D5D39-0F1F26,D3D3D2-2C2C2D")
sys.toast("Result: "..txt:atrim())
txt, info = img:ocr_text({ engine = "paddle", lang = "ppocr_ch" })
sys.toast("Result: "..txt:atrim())
Note: Uses functions outside this chapter sys.toast
, string.atrim
Legacy examples (not recommended)
local img = image.load_file(XXT_SCRIPTS_PATH..'/1.png')
local txt = img:ocr_text()
sys.toast("Result: "..txt:atrim())
local txt = img:ocr_text("eng", "9D5D39-0F1F26,D3D3D2-2C2C2D")
sys.toast("Result: "..txt:atrim())
local txt = img:ocr_text("eng", { {0x9D5D39, 0x0F1F26}, {0xD3D3D2, 0x2C2C2D} })
sys.toast("Result: "..txt:atrim())
local txt = img:ocr_text({ lang = "chi_sim", white_list = "你我他" })
sys.toast("Result: "..txt:atrim())
local txt = img:ocr_text({ lang = "eng", white_list = "1234567890" }, "9D5D39-0F1F26,D3D3D2-2C2C2D")
sys.toast("Result: "..txt:atrim())
Note: Uses functions outside this chapter sys.toast
, string.atrim