if (detector.isOperational() && bitmap != null) {
//BA.Log("detector is operational");
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray<TextBlock> textBlocks = detector.detect(frame);
String blocks = "";
String lines = "";
String words = "";
for (int index = 0; index < textBlocks.size(); index++) {
//extract scanned text blocks here
TextBlock tBlock = textBlocks.valueAt(index);
blocks = blocks + tBlock.getValue() + "\n" + "\n";
for (Text line : tBlock.getComponents()) {
//extract scanned text lines here
lines = lines + line.getValue() + "\n";
for (Text element : line.getComponents()) {
//extract scanned text words here
words = words + element.getValue() + ", ";
}
}
}
if (textBlocks.size() == 0) {
if (ba.subExists(eventName + "_error_result")) {
ba.raiseEventFromDifferentThread(ba.applicationContext, null, 0, eventName + "_error_result", true, new Object[]
{"Nothing Found!"});
}
} else {
if (ba.subExists(eventName + "_blocks_result")) {
ba.raiseEventFromDifferentThread(ba.applicationContext, null, 0, eventName + "_blocks_result", true, new Object[]
{blocks});
}
if (ba.subExists(eventName + "_lines_result")) {
ba.raiseEventFromDifferentThread(ba.applicationContext, null, 0, eventName + "_lines_result", true, new Object[]
{lines});
}
if (ba.subExists(eventName + "_words_result")) {
ba.raiseEventFromDifferentThread(ba.applicationContext, null, 0, eventName + "_words_result", true, new Object[]
{words});
}
}
} else {
if (ba.subExists(eventName + "_error_result")) {
ba.raiseEventFromDifferentThread(ba.applicationContext, null, 0, eventName + "_error_result", true, new Object[]
{"Could not set up the detector!"});
}
}