我有一个带有OpenCV的Android应用,该应用应该能够在运行时更改JavaCameraView的框架大小。
因为对交付的帧进行了大量处理,所以我在App开始时将帧的分辨率设置为320 x280。我这样做是:
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对象。我有什么想念的吗?
最佳答案
好吧,最后我自己找到了。其实这很容易,但是我没有想到。我只需要重新启动我的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();
}
}