SurfaceView中的特定区域

时间:2018-11-16 15:47:42

标签: android

我需要一点帮助。我添加了Google Vision API以检测图像中的文本,为此,图像来自相机,因此它是动态的。相机放置在SurfaceView上,并捕获在surfaceView上找到的文本。我需要SurfaceView可以捕获整个图像的功能,但是文本仅取自我定义的特定区域。简而言之,“在摄像机中添加限制(如矩形),以便图像处理的数据/文本仅来自该矩形”

mCameraSource = new CameraSource.Builder(this, textRecognizer)
        .setFacing(CameraSource.CAMERA_FACING_BACK)
        .setRequestedPreviewSize(1280, 1024)
        .setAutoFocusEnabled(true)
        .setRequestedFps(2.0f)
        .build();

mSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        try {
            if (ActivityCompat.checkSelfPermission(RechargeActivity.this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {

                ActivityCompat.requestPermissions(RechargeActivity.this,
                        new String[]{Manifest.permission.CAMERA},
                        RequestCameraPermissionID);
                return;
            }
            mCameraSource.start(mSurfaceView.getHolder());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        mCameraSource.stop();
    }
});

0 个答案:

没有答案