I had scan the image using Vision Kit framework and I was able to extract data in string but I want it in key value pair such like dictionary( [String: Any] ).
private var ocrRequest = VNRecognizeTextRequest(completionHandler: nil)
ocrRequest = VNRecognizeTextRequest { (request, error) in
guard let observations = request.results as? [VNRecognizedTextObservation] else { return }
var ocrText = ""
for observation in observations {
guard let topCandidate = observation.topCandidates(1).first else { return }
ocrText += topCandidate.string + "\n"
}
DispatchQueue.main.async {
self.ocrTextView.text = ocrText
self.scanButton.isEnabled = true
}
}
Output of the Observation String:
East Repair Inc.
Invoice #
US-001
Invoice Date
11/02/2019
P.O.#
2312/2019
Due Date
26/02/2019
and I need an output like:
{
"marchantName": "East Repair Inc.",
"invoiceNumber": "US-001",
"invoiceDate": "11/02/2019"
.
.
.
}