如何在NDK中获取相机方向

时间:2018-12-03 13:47:26

标签: android android-ndk android-camera2 arcore

我从项目的NDK端的ARCore获取NDK_Image。 由于摄像机的方向,我的AImage即将旋转。

如何在NDK中获取相机方向的值

在Camera NDK文档中,我找到了这个ACAMERA_JPEG_ORIENTATION

它甚至提供了示例代码:

$request = new Request(
        $method['httpMethod'],
        $url,
        ['content-type' => 'application/json'],
        $postBody ? json_encode($postBody) : ''
    );

但是它没有说明如何使用,而且我找不到private int getJpegOrientation(CameraCharacteristics c, int deviceOrientation) { if (deviceOrientation == android.view.OrientationEventListener.ORIENTATION_UNKNOWN) return 0; int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION); // Round device orientation to a multiple of 90 deviceOrientation = (deviceOrientation + 45) / 90 * 90; // Reverse device orientation for front-facing cameras boolean facingFront = c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT; if (facingFront) deviceOrientation = -deviceOrientation; // Calculate desired JPEG orientation relative to camera orientation to make // the image upright relative to the device orientation int jpegOrientation = (sensorOrientation + deviceOrientation + 360) % 360; return jpegOrientation; } 的库。

将是一个很好的示例,说明如何在NDK中获得相机方向。谢谢!

1 个答案:

答案 0 :(得分:0)

该示例代码在Java中存在。

在C ++中,您可以使用标签ACAMERA_SENSOR_ORIENTATION和标签ACAMERA_LENS_FACING调用 ACameraManager_getCameraCharacteristics()

OrientationEventListener.ORIENTATION_UNKNOWNconstant -1CameraCharacteristics.LENS_FACING_FRONTACAMERA_LENS_FACING_FRONT0