Rotate camera JavaCameraView

asked 2015-07-15 09:21:02 -0600

rapsnapps gravatar image

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?

edit retag flag offensive close merge delete

Comments

where i should put this code ?

Hanz gravatar imageHanz ( 2017-03-11 02:42:52 -0600 )edit