本文整理汇总了Java中com.google.android.gms.vision.text.Text类的典型用法代码示例。如果您正苦于以下问题:Java Text类的具体用法?Java Text怎么用?Java Text使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Text类属于com.google.android.gms.vision.text包,在下文中一共展示了Text类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterInvalidDetections
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
private List<Text> filterInvalidDetections(Detector.Detections<TextBlock> items) {
List<Text> result = new ArrayList<>();
SparseArray<TextBlock> detectedItems = items.getDetectedItems();
for (int i = 0; i < detectedItems.size(); ++i) {
TextBlock textBlock = detectedItems.valueAt(i);
// Get sub-components and extract only lines
List<? extends Text> components = textBlock.getComponents();
for (Text component : components) {
String value = component.getValue();
if (component instanceof Line
&& value != null
&& !value.isEmpty()
&& isFoodRelated((value))) {
result.add(component);
} else {
Log.d(TAG, "filterInvalidDetections: sub-component is not a Line, should we go deeper?");
}
}
}
return result;
}
示例2: draw
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
/**
* Draws the text block annotations for position, size, and raw value on the supplied canvas.
*/
@Override
public void draw(Canvas canvas) {
Text text = mText;
if (text == null) {
return;
}
// Draws the bounding box around the TextBlock.
RectF rect = new RectF(text.getBoundingBox());
rect.left = translateX(rect.left);
rect.top = translateY(rect.top);
rect.right = translateX(rect.right);
rect.bottom = translateY(rect.bottom);
canvas.drawRect(rect, sRectPaint);
// Removing the text on top of the overlay
// Break the text into multiple lines and draw each one according to its own bounding box.
/*List<? extends Text> textComponents = text.getComponents();
for (Text currentText : textComponents) {
float left = translateX(currentText.getBoundingBox().left);
float bottom = translateY(currentText.getBoundingBox().bottom);
canvas.drawText(currentText.getValue(), left, bottom, sTextPaint);
}*/
}
示例3: getBoundingBox
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
public Rect getBoundingBox() {
if(mBoundingBox == null) {
int top = Integer.MAX_VALUE, bottom = 0, right = 0, left = Integer.MAX_VALUE;
for (Text text : getComponents()) {
top = (text.getBoundingBox().top < top ? text.getBoundingBox().top : top);
bottom = (text.getBoundingBox().bottom > bottom ? text.getBoundingBox().bottom : bottom);
left = (text.getBoundingBox().left < left ? text.getBoundingBox().left : left);
right = (text.getBoundingBox().right > right ? text.getBoundingBox().right : right);
}
mBoundingBox = new Rect(left, top, right, bottom);
}
return mBoundingBox;
}
示例4: PinGraphic
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
public PinGraphic(GraphicOverlay overlay, Text text, Bitmap imagePinBitmap, SearchResultContainer searchResult, Handler mainHandler) {
super(overlay);
mText = text;
mImagePinBitmap = imagePinBitmap;
mSearchResult = searchResult;
mMainHandler = mainHandler;
init();
// Redraw the overlay, as this graphic has been added.
postInvalidate();
}
示例5: contains
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
/**
* Checks whether a point is within the bounding box of this graphic.
* The provided point should be relative to this graphic's containing overlay.
* @param x An x parameter in the relative context of the canvas.
* @param y A y parameter in the relative context of the canvas.
* @return True if the provided point is contained within this graphic's bounding box.
*/
public boolean contains(float x, float y) {
Text text = mText;
if (text == null) {
return false;
}
RectF rect = new RectF(text.getBoundingBox());
rect.left = translateX(rect.left);
rect.top = translateY(rect.top);
rect.right = translateX(rect.right);
rect.bottom = translateY(rect.bottom);
return (rect.left < x && rect.right > x && rect.top < y && rect.bottom > y);
}
示例6: performOCR
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
private String performOCR(Bitmap bitmap) {
getImageUri(OcrIdActivity.this, bitmap);
String textResult = "";
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
TextRecognizer textRecognizer = new TextRecognizer.Builder(this).build();
SparseArray<TextBlock> textblock = textRecognizer.detect(frame);
TextBlock tb = null;
List<Text> texto = new ArrayList<>();
for (int i = 0; i < textblock.size(); i++) {
tb = textblock.get(textblock.keyAt(i));
Log.e("TEXT", tb.toString() + "");
texto.addAll(tb.getComponents());
}
for (Text t : texto) {
for (Text t2 : t.getComponents()) {
textResult += t2.getValue() + " ";
}
textResult += "\n";
}
if (!textResult.equals("")) {
bitmap.recycle();
return textResult;
} else {
Toast toast = Toast.makeText(this, R.string.ocr_fail, Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP, 0, 0);
toast.show();
return "";
}
}
示例7: receiveDetections
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
if (!mOperating) {
if (mCurrentStatus != Status.LOADING) {
sendOnStatusChanged(Status.OFF);
}
return;
}
mOcrGraphicOverlay.clear();
List<Text> list = filterInvalidDetections(detections);
Status newStatus = Status.DETECTING;
for (Text text : list) {
// Check if the text block is contained inside the oval graphic overlay
if (mMaskViewContainer.contains(text)) {
Log.d(TAG, "receiveDetections: text [" + text.getValue() + "]");
/*SearchResultContainer searchResult = mPreferenceManager.getSearchResult(text.getValue());
// If i've got results for that text in the preferences, show the rect
if (searchResult != null && !searchResult.getImages().isEmpty()) {
Log.d(TAG, "receiveDetections: got results in memory");
// addNewPinGraphic(text, searchResult);
addRect(text);
} else if (searchResult == null) {
Log.d(TAG, "receiveDetections: no results in memory, loading...");
// No UI here
newStatus = Status.LOADING;
} else {
// NO OP
// If i have search results in the prefs but the item list is null or empty then just fail silently
}*/
/* SearchResultContainer searchResult = mPreferenceManager.getSearchResult(text.getValue());
// If i've got results for that text in the preferences
if (searchResult != null && !searchResult.getImages().isEmpty()) {
}*/
SearchResultContainer searchResult = mPreferenceManager.getSearchResult(text.getValue());
Detection detection = new Detection(text.getValue());
// If i've got results for that text in the preferences, show the rect
if (searchResult != null && !searchResult.getImages().isEmpty()) {
detection.setContainer(searchResult);
addNewPinGraphic(text, searchResult);
} else {
addRect(text);
}
RxBus.getInstance().postToEventBus(new NewDetectionFoundEvent(detection));
}
}
sendOnStatusChanged(newStatus);
}
示例8: addRect
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
private void addRect(final Text text) {
RectGraphic rectGraphic = new RectGraphic(mOcrGraphicOverlay, text);
mOcrGraphicOverlay.add(rectGraphic);
}
示例9: addNewPinGraphic
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
private void addNewPinGraphic(Text text, SearchResultContainer searchResult) {
PinGraphic pinGraphic = new PinGraphic(mOcrGraphicOverlay, text, mPinBitmap, searchResult, mMainHandler);
mOcrGraphicOverlay.add(pinGraphic);
}
示例10: getText
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
public Text getText() {
return mText;
}
示例11: itemInsideContainerWindowBoundingBox
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
private boolean itemInsideContainerWindowBoundingBox(Text item) {
if(item.getBoundingBox().bottom < mOcrWindowContainerBoundingBox.bottom)
return true;
return false;
}
示例12: itemBelowOrAboveWindowBoundingBox
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
private boolean itemBelowOrAboveWindowBoundingBox(Text item) {
if(item.getBoundingBox().bottom > mOcrWindowBoundingBox.bottom ||
item.getBoundingBox().top < mOcrWindowBoundingBox.top)
return true;
return false;
}
示例13: itemInsideWindowBoundingBox
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
private boolean itemInsideWindowBoundingBox(Text item) {
return mOcrWindowBoundingBox.contains(item.getBoundingBox().left, item.getBoundingBox().top, item.getBoundingBox().right, item.getBoundingBox().bottom);
}
示例14: OcrGraphic
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
OcrGraphic(GraphicOverlay overlay, Text text, boolean isSelected) {
this(overlay);
mText = text;
mIsSelected = isSelected;
}
示例15: getTextBlock
import com.google.android.gms.vision.text.Text; //导入依赖的package包/类
public Text getTextBlock() {
return mText;
}