Ask Your Question

rapsnapps's profile - activity

2019-10-03 05:31:20 -0600 received badge  Notable Question (source)
2017-11-22 05:38:27 -0600 received badge  Popular Question (source)
2015-07-15 09:26:37 -0600 asked a question Rotate camera JavaCameraView

I'm using JavaCameraView. This is Android application and it supports both Portrait and Landscape modes. I am able to set correct preview and picture size for camera BUT for some reason rotation parameter is ignored and preview is only OK in landscape mode. This is the code I use to set orientation:

private void setCameraDisplayOrientation(Camera camera) {
    int cameraId = getCameraId();
    android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
    android.hardware.Camera.getCameraInfo(cameraId, info);

    WindowManager windowManager = (WindowManager) getContext()
            .getSystemService(Context.WINDOW_SERVICE);

    int rotation = windowManager.getDefaultDisplay().getRotation();
    int degrees = 0;

    switch (rotation) {
        case Surface.ROTATION_0:
            degrees = 0;
            break;
        case Surface.ROTATION_90:
            degrees = 90;
            break;
        case Surface.ROTATION_180:
            degrees = 180;
            break;
        case Surface.ROTATION_270:
            degrees = 270;
            break;
    }

    camera.setDisplayOrientation((info.orientation - degrees + 360) % 360);
}

Obviously I can rotate picture in onCameraFrame but it looks like waste of resources to me. Does OpenCV camera even support orientation other than Landscape?