3

I have an Android App with OpenCV which should be able to change the frame size of the JavaCameraView at runtime. Because a lot processing on the delivered frame I set the resolution of the frame at App start on 320 x 280. I do this like that:

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

I created a RadioButton Group in which I can choose the resolution for the frame. Here is my code;

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();
            }
        }
    });

In fact, nothing happens to the resolution of the frame when I choose another resolution. Of course I also tried to reinitiate the cameraView object. Is there anything I miss?

1 Answer 1

3

Well, finaly I found it out by myself. Actually it was very easy but something I didn't think about. I just had to restart my cameraView Object. Here is my code:

@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();
            }
        }

Not the answer you're looking for? Browse other questions tagged or ask your own question.