Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Computer vision 文本识别应用程序_Computer Vision_Ocr_Vision_Android Vision_Text Recognition - Fatal编程技术网

Computer vision 文本识别应用程序

Computer vision 文本识别应用程序,computer-vision,ocr,vision,android-vision,text-recognition,Computer Vision,Ocr,Vision,Android Vision,Text Recognition,现在我正在尝试制作一款可以识别文本的相机应用程序。为此,我使用了这些信息。本网站介绍如何制作全屏阅读器。但我需要将Mobile Vision文本扫描仪设置为活动的小矩形(如图所示) 我通过在裁剪图像的检测器前面集成“过滤器”(在我的例子中,是图像中心的一行文本)来实现这一功能。请看下面的代码: public class LineDetector extends Detector { Detector mDelegate; public LineDetector(Detecto

现在我正在尝试制作一款可以识别文本的相机应用程序。为此,我使用了这些信息。本网站介绍如何制作全屏阅读器。但我需要将Mobile Vision文本扫描仪设置为活动的小矩形(如图所示)


我通过在裁剪图像的检测器前面集成“过滤器”(在我的例子中,是图像中心的一行文本)来实现这一功能。请看下面的代码:

public class LineDetector extends Detector { 
    Detector mDelegate;

    public LineDetector(Detector delegate) {
        mDelegate = delegate;
    }

    @Override
    public SparseArray detect(Frame frame) {
        int width = frame.getMetadata().getWidth();
        int height = frame.getMetadata().getHeight();

        int mBoxHeight = height;
        int mBoxWidth = Math.toIntExact(Math.round(mBoxHeight * ConstantsPool.CROP_BOX_ASPECT_RATIO));

        int right = (width / 2) + (mBoxWidth / 2);
        int left = (width / 2) - (mBoxWidth / 2);
        int bottom = height;
        int top = 0;

        YuvImage yuvImage = new YuvImage(frame.getGrayscaleImageData().array(), ImageFormat.NV21, width, height, null);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        yuvImage.compressToJpeg(new Rect(left, top, right, bottom), 100, byteArrayOutputStream);
        byte[] jpegArray = byteArrayOutputStream.toByteArray();
        Bitmap bitmap = BitmapFactory.decodeByteArray(jpegArray, 0, jpegArray.length);

        Frame croppedFrame = new Frame.Builder()
            .setBitmap(bitmap)
            .setRotation(frame.getMetadata().getRotation())
            .build();
        return mDelegate.detect(croppedFrame);
    }

    @Override
    public boolean isOperational() {
        return mDelegate.isOperational();
    }

    @Override
    public boolean setFocus(int id) {
        return mDelegate.setFocus(id);
    }
}
然后您可以通过以下方式使用它:

TextRecognizer textRecognizer = new TextRecognizer.Builder(this).build();
LineDetector lineDetector = new LineDetector(textRecognizer);
lineDetector.setProcessor(...);
...
Camera2Source camera2Source = new Camera2Source.Builder(getContext(), lineDetector).build();
如果你有任何问题,尽管问


Tom

小矩形(如图所示)-这不清楚。图像中的矩形是否由用户通过设备屏幕控制,我们是否有图像中该矩形的坐标信息?请在你的问题中提供更多细节.我已经添加了一张所需结果的图片。您可以看到,在这种情况下,应用程序不会尝试读取所有信息,而只读取矩形中的信息。(相机是全屏的,但读取仅在该区域工作)。