安卓移动视觉文本识别缩放到发现的坐标。

5
我正在使用Google的移动视觉API来识别静态位图中的文本(数字)。现在,我想放大数字被发现的位置。 以下是我如何扫描位图并获取x和y坐标的方法:

Point[] p = textBlock.getCornerPoints();

public void Test(Bitmap bitmap) {
    Context context = getApplicationContext();
    TextRecognizer ocrFrame = new TextRecognizer.Builder(context).build();
    Frame frame = new Frame.Builder().setBitmap(bitmap).build();
    ByteBuffer byteBuffer = frame.getGrayscaleImageData();

    if (ocrFrame.isOperational()) {
        Log.e(TAG, "Textrecognizer is operational");
    }
    SparseArray<TextBlock> textBlocks = ocrFrame.detect(frame);

    for (int i = 0; i < textBlocks.size(); i++) {
        TextBlock textBlock = textBlocks.get(textBlocks.keyAt(i));
        String value = textBlock.getValue();
        Point[] p = textBlock.getCornerPoints();
        Log.e(TAG, "something is happening");
    }
}

此外,我正在使用TouchImageView来显示位图。现在我正在使用获取的坐标调用setZoom方法,如下所示:

touchImageView.setZoom(1F, 210F, 748F, ImageView.ScaleType.CENTER);

但是它缩放到了错误的位置,我真的不知道为什么。有人可以给我一些提示吗?

(https://github.com/MikeOrtiz/TouchImageView/blob/master/src/com/ortiz/touch/TouchImageView.java)

编辑:好的,我弄清楚了,比例类型做了一些我不理解的事情。问题在于setZoom,我想。我必须将位图的坐标转换为Touchimageview的坐标。

编辑2:解决方案:错误在于直接传递x和y坐标,但是setZoom接受值介于0和1之间。

int BitmapHeight = photo.getHeight();
int BitmapWidth = photo.getWidth();

int FoundX = p[0].x;
int FoundY = p[0].y;

float DividerX = BitmapWidth / (float)FoundX;
float DividerY = BitmapHeight / (float)FoundY;

float ZoomX = 1 / (float)DividerX;
float ZoomY = 1 / (float)DividerY;

touchImageView.setZoom(touchImageView.getMaxZoom(), ZoomX, ZoomY, ImageView.ScaleType.CENTER);

解决了你的问题吗? - Bincy Baby
是的,请看我的第二次编辑。 - BR75
1个回答

0

我正在使用这个库。 - BR75

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接