R. *_*Kut 5 android zoom touchimageview
我正在使用Googles Mobile Vision API识别静态位图中的文本(数字).现在我想放大到找到号码的地方.
这就是我扫描Bitmap并获取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");
}
}
Run Code Online (Sandbox Code Playgroud)
此外,我使用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的坐标.
EDIT2:解决方案:错误是直接传递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);
Run Code Online (Sandbox Code Playgroud)
您可以使用这个谷歌库https://developers.google.com/vision/android/text-overview。您可以在这里找到示例https://codelabs.developers.google.com/codelabs/mobile-vision-ocr
通过在 android gradle 文件中添加以下内容
compile 'com.google.android.gms:play-services-vision:15.0.0'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
317 次 |
| 最近记录: |