如何在 NDK 中获取相机方向
How get camera orientation in NDK
我在项目的 NDK 端从 ARCore 获取 NDK_Image。
由于相机方向,我的 AImage 正在旋转。
如何在 NDK 中获取相机方向的值?
我在 Camera NDK 文档中找到了这个 ACAMERA_JPEG_ORIENTATION
它甚至给出了一个代码示例:
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;
}
但是没有说明如何使用,而且我找不到CameraCharascteristics
的库。
这将是一个很好的示例,说明如何在 NDK 中获取相机方向。谢谢!
Java 中的示例代码是错误的。
在 C++ 中,您可以使用标记 ACAMERA_SENSOR_ORIENTATION and tag ACAMERA_LENS_FACING.
调用 ACameraManager_getCameraCharacteristics()
OrientationEventListener.ORIENTATION_UNKNOWN
是一个constant -1. CameraCharacteristics.LENS_FACING_FRONT
or ACAMERA_LENS_FACING_FRONT是0
.
我在项目的 NDK 端从 ARCore 获取 NDK_Image。 由于相机方向,我的 AImage 正在旋转。
如何在 NDK 中获取相机方向的值?
我在 Camera NDK 文档中找到了这个 ACAMERA_JPEG_ORIENTATION
它甚至给出了一个代码示例:
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;
}
但是没有说明如何使用,而且我找不到CameraCharascteristics
的库。
这将是一个很好的示例,说明如何在 NDK 中获取相机方向。谢谢!
Java 中的示例代码是错误的。
在 C++ 中,您可以使用标记 ACAMERA_SENSOR_ORIENTATION and tag ACAMERA_LENS_FACING.
调用 ACameraManager_getCameraCharacteristics()OrientationEventListener.ORIENTATION_UNKNOWN
是一个constant -1. CameraCharacteristics.LENS_FACING_FRONT
or ACAMERA_LENS_FACING_FRONT是0
.