本文整理汇总了Java中com.google.android.gms.vision.text.TextBlock.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java TextBlock.getValue方法的具体用法?Java TextBlock.getValue怎么用?Java TextBlock.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.vision.text.TextBlock
的用法示例。
在下文中一共展示了TextBlock.getValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: detectText
import com.google.android.gms.vision.text.TextBlock; //导入方法依赖的package包/类
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());
}
}
}
示例2: onTap
import com.google.android.gms.vision.text.TextBlock; //导入方法依赖的package包/类
/**
* 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;
}
示例3: receiveDetections
import com.google.android.gms.vision.text.TextBlock; //导入方法依赖的package包/类
/**
* 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) {
mGraphicOverlay.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) {
final String wort = item.getValue();
if(wort.length() > 1 && Character.isUpperCase(wort.charAt(0)) && wort.matches("[A-Za-z-]+") && wort.charAt(wort.length() - 1) != '-') {
Log.d("OCR", "Name detected: " + wort);
// Show AccountDetailActivity
new Thread(new Runnable() {
@Override
public void run() {
DownloadIntentService.startService(context, OcrCaptureActivity.DOWNLOAD_REQUEST_CODE, wort);
}
}).start();
} else {
Log.d("OcrDetectorProcessor", "Text detected! " + item.getValue());
}
}
}
}
示例4: onTap
import com.google.android.gms.vision.text.TextBlock; //导入方法依赖的package包/类
/**
* 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
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
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) {
Log.d(TAG, "text data is being displayed! " + text.getValue());
//Show the string.
String capturedText = text.getValue();
capturedText = capturedText.substring(0,1).toUpperCase() + capturedText.substring(1).toLowerCase();
textView.setText(capturedText);
}
else {
Log.d(TAG, "text data is null");
}
}
else {
Log.d(TAG,"no text detected");
}
return text != null;
}
示例5: receiveDetections
import com.google.android.gms.vision.text.TextBlock; //导入方法依赖的package包/类
/**
* 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) {
mGraphicOverlay.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) {
if (item.getValue().contains("INSTITUTO FEDERAL ELECTORAL")) {
documentIdentifier.setType(Constants.IFEB);
} else if (item.getValue().contains("INSTITUTO NACIONAL ELECTORAL")) {
Log.d("OcrDetectorProcessor", "INE E " + item.getValue());
documentIdentifier.setType(Constants.IFEE);
}
}
//OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item);
//mGraphicOverlay.add(graphic);
}
}
示例6: onTap
import com.google.android.gms.vision.text.TextBlock; //导入方法依赖的package包/类
/**
* 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 = mGraphicOverlay.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;
}
示例7: receiveDetections
import com.google.android.gms.vision.text.TextBlock; //导入方法依赖的package包/类
@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
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("Processor", "Text detected! " + item.getValue());
}
}
}
示例8: receiveDetections
import com.google.android.gms.vision.text.TextBlock; //导入方法依赖的package包/类
/**
* 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) {
mGraphicOverlay.clear();
final 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(mGraphicOverlay, item);
mGraphicOverlay.add(graphic);
}
}
示例9: onTap
import com.google.android.gms.vision.text.TextBlock; //导入方法依赖的package包/类
/**
* 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;
}
示例10: receiveDetections
import com.google.android.gms.vision.text.TextBlock; //导入方法依赖的package包/类
/**
* 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) {
mGraphicOverlay.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(mGraphicOverlay, item);
mGraphicOverlay.add(graphic);
}
}
示例11: onActivityResult
import com.google.android.gms.vision.text.TextBlock; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PHOTO_REQUEST && resultCode == RESULT_OK) {
launchMediaScanIntent();
try {
Bitmap bitmap = decodeBitmapUri(this, imageUri);
if (detector.isOperational() && bitmap != null) {
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) {
scanResults.setText("Scan Failed: Found nothing to scan");
} else {
scanResults.setText(scanResults.getText() + "Blocks: " + "\n");
scanResults.setText(scanResults.getText() + blocks + "\n");
scanResults.setText(scanResults.getText() + "---------" + "\n");
scanResults.setText(scanResults.getText() + "Lines: " + "\n");
scanResults.setText(scanResults.getText() + lines + "\n");
scanResults.setText(scanResults.getText() + "---------" + "\n");
scanResults.setText(scanResults.getText() + "Words: " + "\n");
scanResults.setText(scanResults.getText() + words + "\n");
scanResults.setText(scanResults.getText() + "---------" + "\n");
}
} else {
scanResults.setText("Could not set up the detector!");
}
} catch (Exception e) {
Toast.makeText(this, "Failed to load Image", Toast.LENGTH_SHORT)
.show();
Log.e(LOG_TAG, e.toString());
}
}
}