Java Code Examples for com.google.android.gms.vision.text.TextBlock#getValue()
The following examples show how to use
com.google.android.gms.vision.text.TextBlock#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OcrCaptureActivity.java From OCR-Reader with MIT License | 6 votes |
/** * onTap is called to capture the first TextBlock under the tap location and return it to * the Initializing Activity. * * @param rawX - the raw position of the tap * @param rawY - the raw position of the tap. * @return true if the activity is ending. */ private boolean onTap(float rawX, float rawY) { OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY); TextBlock text = null; if (graphic != null) { text = graphic.getTextBlock(); if (text != null && text.getValue() != null) { Intent data = new Intent(); data.putExtra(TextBlockObject, text.getValue()); setResult(CommonStatusCodes.SUCCESS, data); finish(); } else { Log.d(TAG, "text data is null"); } } else { Log.d(TAG,"no text detected"); } return text != null; }
Example 2
Source File: OcrCaptureActivity.java From Moneycim with MIT License | 6 votes |
/** * onTap is called to capture the first TextBlock under the tap location and return it to * the Initializing Activity. * * @param rawX - the raw position of the tap * @param rawY - the raw position of the tap. * @return true if the activity is ending. */ private boolean onTap(float rawX, float rawY) { OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY); TextBlock text = null; if (graphic != null) { text = graphic.getTextBlock(); if (text != null && text.getValue() != null) { Intent data = new Intent(); data.putExtra(TextBlockObject, text.getValue()); setResult(CommonStatusCodes.SUCCESS, data); finish(); } else { Log.d(TAG, "text data is null"); } } else { Log.d(TAG,"no text detected"); } return text != null; }
Example 3
Source File: OcrCaptureActivity.java From Questor with MIT License | 6 votes |
/** * onTap is called to capture the first TextBlock under the tap location and return it to * the Initializing Activity. * * @param rawX - the raw position of the tap * @param rawY - the raw position of the tap. * @return true if the activity is ending. */ private boolean onTap(float rawX, float rawY) { OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY); TextBlock text = null; if (graphic != null) { text = graphic.getTextBlock(); if (text != null && text.getValue() != null) { Intent data = new Intent(); data.putExtra(TextBlockObject, text.getValue()); setResult(CommonStatusCodes.SUCCESS, data); finish(); } else { Log.d(TAG, "text data is null"); } } else { Log.d(TAG,"no text detected"); } return text != null; }
Example 4
Source File: OcrCaptureActivity.java From android-vision with Apache License 2.0 | 6 votes |
/** * onTap is called to speak the tapped TextBlock, if any, out loud. * * @param rawX - the raw position of the tap * @param rawY - the raw position of the tap. * @return true if the tap was on a TextBlock */ private boolean onTap(float rawX, float rawY) { OcrGraphic graphic = graphicOverlay.getGraphicAtLocation(rawX, rawY); TextBlock text = null; if (graphic != null) { text = graphic.getTextBlock(); if (text != null && text.getValue() != null) { Log.d(TAG, "text data is being spoken! " + text.getValue()); // Speak the string. tts.speak(text.getValue(), TextToSpeech.QUEUE_ADD, null, "DEFAULT"); } else { Log.d(TAG, "text data is null"); } } else { Log.d(TAG,"no text detected"); } return text != null; }
Example 5
Source File: OcrCaptureActivity.java From android-vision with Apache License 2.0 | 6 votes |
/** * onTap is called to capture the first TextBlock under the tap location and return it to * the Initializing Activity. * * @param rawX - the raw position of the tap * @param rawY - the raw position of the tap. * @return true if the activity is ending. */ private boolean onTap(float rawX, float rawY) { OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY); TextBlock text = null; if (graphic != null) { text = graphic.getTextBlock(); if (text != null && text.getValue() != null) { Intent data = new Intent(); data.putExtra(TextBlockObject, text.getValue()); setResult(CommonStatusCodes.SUCCESS, data); finish(); } else { Log.d(TAG, "text data is null"); } } else { Log.d(TAG,"no text detected"); } return text != null; }
Example 6
Source File: ImageTextReader.java From loco-answers with GNU General Public License v3.0 | 5 votes |
public String[] getTextFromBitmap2(Bitmap src) { if (textRecognizer.isOperational() && src != null) { Frame frame = new Frame.Builder().setBitmap(src).build(); SparseArray<TextBlock> textBlocks = textRecognizer.detect(frame); String blocks = ""; String lines = ""; for (int index = 0; index < textBlocks.size(); index++) { TextBlock tBlock = textBlocks.valueAt(index); blocks = blocks + tBlock.getValue() + "\n"; for (Text line : tBlock.getComponents()) { lines = lines + line.getValue() + "\n"; } } if (textBlocks.size() == 0) { // Log.d(TAG, "getTextFromBitmap: Scan Failed: Found nothing to scan"); return new String[]{"Scan Failed: Found nothing to scan"}; } else { String[] textOnScreen = lines.split("\n"); int lineCount = textOnScreen.length; if (lineCount > 3) { String question = ""; for (int i = 0; i < lineCount - 3; i++) { question += textOnScreen[i]; } return new String[]{question, textOnScreen[lineCount - 3], textOnScreen[lineCount - 2], textOnScreen[lineCount - 1]}; } return new String[]{"Scan Failed: Could not read options"}; } } else { Log.d(TAG, "getTextFromBitmap: Could not set up the detector!"); return new String[]{"Scan Failed: Could not set up the detector!"}; } }
Example 7
Source File: TextProcessor.java From camerakit-android with MIT License | 5 votes |
@Override public void receiveDetections(Detector.Detections<TextBlock> detections) { SparseArray<TextBlock> detectedItems = detections.getDetectedItems(); for (int i = 0; i < detectedItems.size(); ++i) { TextBlock item = detectedItems.valueAt(i); if (item != null && item.getValue() != null) { CameraKitTextDetect event = new CameraKitTextDetect(new CameraKitTextBlock(item)); mEventDispatcher.dispatch(event); callback.callback(event); } } }
Example 8
Source File: OcrCaptureActivity.java From Document-Scanner with GNU General Public License v3.0 | 5 votes |
/** * onTap is called to capture the first TextBlock under the tap location and return it to * the Initializing Activity. * * @param rawX - the raw position of the tap * @param rawY - the raw position of the tap. * @return true if the activity is ending. */ private boolean onTap(float rawX, float rawY) { OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY); TextBlock text = null; if (graphic != null) { text = graphic.getTextBlock(); if (text != null && text.getValue() != null) { ocr_text.setClickable(true); String ocrtext = ocr_text.getText().toString(); if (!ocrtext.isEmpty()) { ocrtext = ocrtext + "\n" + text.getValue(); ocr_text.setText(ocrtext); } else { ocr_text.setText(text.getValue()); } } else { Log.d(TAG, "text data is null"); } } else { Log.d(TAG, "no text detected"); } return text != null; }
Example 9
Source File: MainActivity.java From text-detector with MIT License | 5 votes |
public void detectText(View view) { Bitmap textBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cat); TextRecognizer textRecognizer = new TextRecognizer.Builder(this).build(); if (!textRecognizer.isOperational()) { new AlertDialog.Builder(this) .setMessage("Text recognizer could not be set up on your device :(") .show(); return; } Frame frame = new Frame.Builder().setBitmap(textBitmap).build(); SparseArray<TextBlock> text = textRecognizer.detect(frame); for (int i = 0; i < text.size(); ++i) { TextBlock item = text.valueAt(i); if (item != null && item.getValue() != null) { detectedTextView.setText(item.getValue()); } } }
Example 10
Source File: OcrDetectorProcessor.java From android-vision with Apache License 2.0 | 5 votes |
/** * Called by the detector to deliver detection results. * If your application called for it, this could be a place to check for * equivalent detections by tracking TextBlocks that are similar in location and content from * previous frames, or reduce noise by eliminating TextBlocks that have not persisted through * multiple detections. */ @Override public void receiveDetections(Detector.Detections<TextBlock> detections) { graphicOverlay.clear(); SparseArray<TextBlock> items = detections.getDetectedItems(); for (int i = 0; i < items.size(); ++i) { TextBlock item = items.valueAt(i); if (item != null && item.getValue() != null) { Log.d("OcrDetectorProcessor", "Text detected! " + item.getValue()); OcrGraphic graphic = new OcrGraphic(graphicOverlay, item); graphicOverlay.add(graphic); } } }
Example 11
Source File: MyTextBlock.java From flutter_mobile_vision with MIT License | 4 votes |
public MyTextBlock(TextBlock textBlock) { this.language = textBlock.getLanguage(); this.value = textBlock.getValue(); this.boundingBox = textBlock.getBoundingBox(); }