opencv4android的相机焦点

问题描述 投票:0回答:1

我想使图像模糊,因此需要更改OpenCV的聚焦模式。我创建了一个新类以继承javacameraview并在该类中设置焦点模式。现在,只需将mopencvcameraview参数更改为崩溃即可。我找不到原因。请看一看,谢谢。另一个问题是如何在javacamera2view中更改相机参数?

MyJavaCameraView

public class MyJavaCameraView extends JavaCameraView {

    public MyJavaCameraView(Context context, int cameraId) {
        super(context, cameraId);
    }

    public MyJavaCameraView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
I want to blur the image, so I need to change the focus mode of OpenCV. I created a new class to inherit javacameraview and set the focus mode in the class. Now just change the mopencvcameraview parameter to crash. I can't find the reason. Please take a look, thank you. Another question is how to change camera parameters in javacamera2view?

    public void setFocusMode() {
        Camera camera = mCamera;
        Camera.Parameters mParameters = camera.getParameters();
        if (camera != null) {
            List<String> supportedFocusModes = mParameters.getSupportedFocusModes();
            if (supportedFocusModes != null && supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) {
                mParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
                camera.setParameters(mParameters);
            }

        }

    }
}

ImageManipulationsActivity

    @Override
    public void onCreate(Bundle savedInstanceState) {
        Log.i(TAG, "called onCreate");
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        setContentView(R.layout.image_manipulations_surface_view);

        mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.image_manipulations_activity_surface_view);
        //Change it to the following crash
        //mOpenCvCameraView = (MyJavaCameraView) findViewById(R.id.image_manipulations_activity_surface_view);
        mOpenCvCameraView.setVisibility(CameraBridgeViewBase.VISIBLE);
        mOpenCvCameraView.setCvCameraViewListener(this);
    }
opencv opencv4android
1个回答
0
投票

我认为您可能会发现更容易使用相机正常拍摄图像,然后再使用openCV进行模糊处理。

这也将使您不必测试和适应不同设备上的不同相机功能。

这里有一些有关图像模糊的OpenCV文档,https://docs.opencv.org/master/d4/d13/tutorial_py_filtering.html

[使用大多数OpenCV文档,我发现通常理解Python示例中的方法,然后参考Android Python类文档将其应用于Android,这通常是一件好事。

© www.soinside.com 2019 - 2024. All rights reserved.