การอ้างอิงเฟรมเวิร์ก MLKitTextRecognitionCommon
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
TextRecognizer
class TextRecognizer : NSObject
โปรแกรมจดจำข้อความที่จดจำข้อความในรูปภาพ
-
แสดงผลโปรแกรมจดจำข้อความตามตัวเลือกที่ระบุ
การใช้งานอินสแตนซ์ TextRecognizer
หลายรายการที่มีภาษาต่างๆ พร้อมกัน
ไม่แนะนำให้ใช้ตัวเลือกดังกล่าว เนื่องจากอาจทำให้ประสิทธิภาพลดลง
คำประกาศ
Swift
class func textRecognizer(options: MLKCommonTextRecognizerOptions) -> Self
พารามิเตอร์
options
|
ตัวเลือกสำหรับการกำหนดค่าโปรแกรมจดจำข้อความ
|
ผลลัพธ์
โปรแกรมจดจำข้อความที่กำหนดค่าด้วยตัวเลือกที่ระบุ
-
ประมวลผลรูปภาพที่ระบุสำหรับการจดจำข้อความ
พารามิเตอร์
image
|
|
completion
|
เครื่องจัดการที่จะโทรกลับในคิวหลักเมื่อการจดจำข้อความเสร็จสมบูรณ์
|
-
แสดงผลการจดจำข้อความในรูปภาพที่ระบุหรือ nil
หากมีข้อผิดพลาด ข้อความ
การจดจำเสียงจะดำเนินการแบบพร้อมกันบนเทรดการโทร
ขอแนะนำให้เรียกใช้เมธอดนี้นอกเทรดหลักเพื่อหลีกเลี่ยงการบล็อก UI เพื่อ
ผลลัพธ์ NSException
จะเพิ่มขึ้นหากมีการเรียกใช้เมธอดนี้ในเทรดหลัก
พารามิเตอร์
image
|
|
error
|
พารามิเตอร์ข้อผิดพลาดที่ไม่บังคับจะสร้างขึ้นเมื่อเกิดข้อผิดพลาดในการรับผลลัพธ์
|
ผลลัพธ์
การจดจำข้อความในรูปภาพที่ระบุหรือ nil
หากมีข้อผิดพลาด
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 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."]]