Use DataScannerViewController Swift for single-line text recognition vision

218 Views Asked by At

Is there a way to customize the RecognizedItem from DataScannerViewController (text scanner from wwdc22) to only contain words up to a new line (so that each recognized item is only one line of text)?

I know that RecognizedItem is able to detect text and where line changes occur, since when I print out the RecognizedItem's description it prints out \n whenever there is a line change.

Right now Recognized Item typically recognizes giant blocks of text but I want it to recognize text line by line so the user can tap on separate lines of text and the code will perform differnt actions, instead of only being able to tap on a giant block that contains multiple lines of text.

-> Using this method:
func dataScanner(_ dataScanner: DataScannerViewController, didTapOn item: RecognizedItem)

Let me know if I should clarify anything or provide code samples, but I just have a pretty standard implementation of DataScannerViewController as shown in the WWDC22 video -> https://developer.apple.com/videos/play/wwdc2022/10025/

I tried accessing the RecognizedTextItem's observation property https://developer.apple.com/documentation/visionkit/recognizeditem/text/3941793-observation but that didn't yield any additional information, it just gave me the bounding box of the large text block which I already know.

The closest thing I have got to single line text detection is using VNRecognizeTextRequests (which is able to detect individual words) but I don't like that implementation since when used in conjunction with DataScannerViewController it causes the entire UI to lag.

0

There are 0 best solutions below