Does anyone have a code snippet showing how to do OCR using LeadTools in real-time? I want the OCR to be for a specific region within the camera preview. I am doing the development on Android.
You can add an OCRZone to the IOCRPage Zone collection prior to calling Recognize.
If there are no zones present in the IOcrZoneCollection prior to calling Recognize, the AutoZone method is called internally and the image is segmented automatically. If there is a zone present, then only that zone is used in the recognition.
Here is some sample code you can use in your Android application:
mOcrEngine = OcrEngineManager.createEngine(OcrEngineType.Advantage);
mOcrEngine.startup(codecsForOCR, "", OCR_RUNTIME_DIRECTORY, sharedLibsPath);
document = mOcrEngine.getDocumentManager().createDocument();
image=imgViewer.getImage();
ocrPage = document.getPages().addPage(image, null);
//the left/top/width/height are from your camera settings
LeadRect rect = new LeadRect(left, top, width, height);
OcrZone zone = new OcrZone();
zone.setBounds(rect).
zone.setZoneType(OcrZoneType.TEXT.getValue());
ocrPage.getZones().addZone(ocrZone);
ocrPage.recognize(null);
If you need any addional assistance with this, feel free to contact our free Technical support for the SDK here: