Dokumentacja platformy MLKitTextRecognitionCommon
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
TextRecognizer
class TextRecognizer : NSObject
Moduł rozpoznawania tekstu, który rozpoznaje tekst na obrazie.
-
Zwraca moduł rozpoznawania tekstu z podanymi opcjami.
Równoczesne korzystanie z wielu instancji TextRecognizer
w różnych językach
nie jest zalecana, ponieważ może prowadzić do pogorszenia wydajności.
Deklaracja
Swift
class func textRecognizer(options: MLKCommonTextRecognizerOptions) -> Self
Parametry
options
|
Opcje konfigurowania modułu rozpoznawania tekstu.
|
Zwracana wartość
Moduł rozpoznawania tekstu skonfigurowany do używania podanych opcji.
-
Przetwarza dany obraz na potrzeby rozpoznawania tekstu.
Parametry
image
|
|
completion
|
Moduł obsługi, z którego można oddzwonić do kolejki głównej po zakończeniu rozpoznawania tekstu.
|
-
Zwraca wynik rozpoznawania tekstu w przypadku danego obrazu lub nil
, jeśli wystąpił błąd. Tekst
jest wykonywane synchronicznie w wątku wywołującym.
Zaleca się wywoływanie tej metody poza wątkiem głównym, aby uniknąć blokowania interfejsu użytkownika. Jako
wynik, jeśli ta metoda zostanie wywołana w wątku głównym, zostanie podniesiony NSException
.
Parametry
image
|
Obraz, do którego chcesz uzyskać wyniki.
|
error
|
Opcjonalny parametr błędu jest wypełniany w przypadku wystąpienia błędu podczas pobierania wyników.
|
Zwracana wartość
Rozpoznawanie tekstu powoduje wyświetlenie danego obrazu lub użycie polecenia nil
, jeśli wystąpił błąd.
O ile nie stwierdzono inaczej, treść tej strony jest objęta licencją Creative Commons – uznanie autorstwa 4.0, a fragmenty kodu są dostępne na licencji Apache 2.0. Szczegółowe informacje na ten temat zawierają zasady dotyczące witryny Google Developers. Java jest zastrzeżonym znakiem towarowym firmy Oracle i jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-07-25 UTC.
[null,null,["Ostatnia aktualizacja: 2025-07-25 UTC."],[[["\u003cp\u003e\u003ccode\u003eTextRecognizer\u003c/code\u003e identifies and extracts text within images.\u003c/p\u003e\n"],["\u003cp\u003eIt offers both synchronous and asynchronous processing options.\u003c/p\u003e\n"],["\u003cp\u003eConcurrent use with varying language settings may impact performance.\u003c/p\u003e\n"],["\u003cp\u003eDirect use on the main thread is discouraged due to potential UI blocking.\u003c/p\u003e\n"]]],["The `TextRecognizer` class recognizes text in images. It can be initialized with specific options via `textRecognizer(options:)`. The `process(_:)` method performs text recognition on an image asynchronously, while `results(in:)` performs it synchronously, returning the recognized text or `nil` if an error occurs. Concurrent usage of multiple `TextRecognizer` instances with different language options may reduce performance. `results(in:)` should not be called on the main thread.\n"],null,["# MLKitTextRecognitionCommon Framework Reference\n\nTextRecognizer\n==============\n\n class TextRecognizer : NSObject\n\nA text recognizer that recognizes text in an image.\n- `\n ``\n ``\n `\n\n ### [textRecognizer(options:)](#/c:objc(cs)MLKTextRecognizer(cm)textRecognizerWithOptions:)\n\n `\n ` \n Returns a text recognizer with the given options.\n\n Concurrent usage of multiple `TextRecognizer` instances with different language\n options is not recommended, since it may lead to performance degradation. \n\n #### Declaration\n\n Swift \n\n class func textRecognizer(options: MLKCommonTextRecognizerOptions) -\u003e Self\n\n #### Parameters\n\n |-----------------|----------------------------------------------|\n | ` `*options*` ` | Options for configuring the text recognizer. |\n\n #### Return Value\n\n An text recognizer configured with the given options.\n- `\n ``\n ``\n `\n\n ### [process(_:)](#/c:objc(cs)MLKTextRecognizer(im)processImage:completion:)\n\n `\n ` \n Processes the given image for text recognition. \n\n #### Declaration\n\n Swift \n\n func process(_ image: ../Protocols.html#/c:objc(pl)MLKCompatibleImage) async throws -\u003e MLKText\n\n #### Parameters\n\n |--------------------|-------------------------------------------------------------------------|\n | ` `*image*` ` | The image to process. |\n | ` `*completion*` ` | Handler to call back on the main queue when text recognition completes. |\n\n- `\n ``\n ``\n `\n\n ### [results(in:)](#/c:objc(cs)MLKTextRecognizer(im)resultsInImage:error:)\n\n `\n ` \n Returns text recognition result in the given image or `nil` if there was an error. The text\n recognition is performed synchronously on the calling thread.\n\n It is advised to call this method off the main thread to avoid blocking the UI. As a\n result, an `NSException` is raised if this method is called on the main thread. \n\n #### Declaration\n\n Swift \n\n func results(in image: ../Protocols.html#/c:objc(pl)MLKCompatibleImage) throws -\u003e MLKText\n\n #### Parameters\n\n |---------------|-------------------------------------------------------------------------------|\n | ` `*image*` ` | The image to get results in. |\n | ` `*error*` ` | An optional error parameter populated when there is an error getting results. |\n\n #### Return Value\n\n Text recognition result in the given image or `nil` if there was an error."]]