如何在运行时更改JavaCameraView的maxFrameSize

时间:2015-08-11 11:09:28

标签: java android opencv

我有一个带OpenCV的Android应用程序,它应该能够在运行时更改JavaCameraView的帧大小。 因为在交付帧上进行了大量处理,我在App开始时将帧的分辨率设置为320 x 280.我这样做:

protected void onCreate(Bundle savedInstanceState) {
    cameraView = (JavaCameraView) findViewById(R.id.cam_view);
    cameraView.setMaxFrameSize(320, 280);
    cameraView.setCvCameraViewListener(this);

我创建了一个RadioButton组,我可以在其中选择帧的分辨率。这是我的代码;

resolutionChange = new Dialog(this);
    resolutionChange.requestWindowFeature(Window.FEATURE_NO_TITLE);
    resolutionChange.setContentView(com.finarx.opencv.camera.R.layout.resdialog);

    RadioGroup resChange = (RadioGroup) resolutionChange.findViewById(com.finarx.opencv.camera.R.id.resChange);
    resChange.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group,
                int checkedId) {
            if (checkedId == com.finarx.opencv.camera.R.id.lowest) {
                cameraView.setMaxFrameSize(320, 280);
                resolutionChange.dismiss();
            } else if (checkedId == com.finarx.opencv.camera.R.id.low) {
                cameraView.setMaxFrameSize(480, 320);
                resolutionChange.dismiss();
            } else if (checkedId == com.finarx.opencv.camera.R.id.vga) {
                cameraView.setMaxFrameSize(640, 480);
                resolutionChange.dismiss();
            } else if (checkedId == com.finarx.opencv.camera.R.id.higher) {
                cameraView.setMaxFrameSize(800, 600);
                resolutionChange.dismiss();
            } else if (checkedId == com.finarx.opencv.camera.R.id.highest) {
                cameraView.setMaxFrameSize(1280, 720);
                resolutionChange.dismiss();
            }
        }
    });

事实上,当我选择其他分辨率时,帧的分辨率没有任何反应。当然我也尝试重新启动cameraView对象。我有什么想念吗?

1 个答案:

答案 0 :(得分:3)

好吧,最后我自己发现了它。实际上这很容易,但我没有想到的事情。我只需要重新启动我的cameraView对象。这是我的代码:

@Override
        public void onCheckedChanged(RadioGroup group,
                int checkedId) {
            if (checkedId == com.finarx.opencv.camera.R.id.lowest) {
                cameraView.setMaxFrameSize(320, 280);
                cameraView.disableView();
                cameraView.enableView();
                resolutionChange.dismiss();
            } else if (checkedId == com.finarx.opencv.camera.R.id.low) {
                cameraView.setMaxFrameSize(480, 320);
                cameraView.disableView();
                cameraView.enableView();
                resolutionChange.dismiss();
            } else if (checkedId == com.finarx.opencv.camera.R.id.vga) {
                cameraView.setMaxFrameSize(640, 480);
                cameraView.disableView();
                cameraView.enableView();
                resolutionChange.dismiss();
            } else if (checkedId == com.finarx.opencv.camera.R.id.higher) {
                cameraView.setMaxFrameSize(800, 600);
                cameraView.disableView();
                cameraView.enableView();
                resolutionChange.dismiss();
            } else if (checkedId == com.finarx.opencv.camera.R.id.highest) {
                cameraView.setMaxFrameSize(1280, 720);
                cameraView.disableView();
                cameraView.enableView();
                resolutionChange.dismiss();
            }
        }